Exercise is good but it won't work by itself.
If you walk 20,000 steps in one day (about eight miles, or 2 to 3 hours), you'll burn off about 1000 calories. You can easily put that 1000 calories back on just by eating eight two-finger KitKats, or four sandwiches, or two or three muffins.
Losing a pound of weight is about 35 miles of walking (70,000 steps).
You can put on weight through eating far far faster than you can burn it off.
So although exercise helps, it's nowhere near as effective as controlling what you eat.
Your body burns 1,300 to 2000 calories a day just to stay warm and alive, before any exercise. The problem with dieting is that your body catches onto this and reduces this daily burn rate. So dieting soon becomes less productive.
Look into fasting (but talk to your doctor first if you have any medical issues that might make it unsafe for you). Fast from midday one day to morning the next (so no eating after midday), or alternate-day fasting, or even go on a fast for several days. (The longest fast was a Scotsman who fasted for over a year: look it up.)
I once fasted for six days: the first two days are awful, but if you can get past the hunger pangs of those two days by staying active and busy, the third day you stop feeling hungry altogether and actually feel slightly euphoric. And by then your body will have burnt off two days worth of calories in keeping itself warm and alive. And there are other proven benefits of fasting.
Look into fasting (there are loads of YouTube videos, and books) if you cannot stop yourself having sugar and treats, but as I said, consult a doctor if you're not in good health.