Now the next thing that I wanna look at is,
some of the more critical debugging steps.
This is one of the big pieces that you're gonna end up finding,
when you write code, you will write buggy code.
It's just the way it is, and one of the most important things that we can have,
after being able to read code is the ability to actually debug it.
You'll notice in this particular case here,
I have my workbook Debugging Basics open.
This is, basically reset the schedule back to January 31st, but
the code cleanup changes we made are in here.
I've also docked my Excel window.
Side by side with my visual basic window, I'm going to get rid of
some stuff that I don't need here, so I get a little bit more space.
So I'm just gonna get rid of the project and properties window.
Get rid of the watches window as well, and let's get rid of the locals window too.
So, what we can see is we have our code here.
And what I'd like to do, is I'd like to actually go through and
show you what ends up happening with this.
Normally, when we run our code, it runs from top to bottom.
But what if I need to step through and see what's actually happening?
Well, in this case, there's actually one of the commands, and
I'm just gonna pull this tool bar off so you can see it here.
This is the debugging toolbar.
It will work when it's snapped up into the top here.
Just want to make sure you know which one it is.
You'll notice that there's this little step into- and
if we click on this guy, it highlights the first line of the sub roll forward.
And if we then go and say, all right well let's go and step into it again.
It highlights, it skips over all of the stuff that's commented out.
None of these guys are going to get executed.
But it says, I am going to do this.
And when we step into this one again, it executes that line,
you can see the marching ants are walking around the border now.
And then it says okay, the next line that I'm gonna do, the yellow arrow is
pointing to it, we're going to do a paste special paste values over B6.
So we'll hit step, and you'll notice that indeed it does exactly that,
it copies the values over, and then it says all right, the next line that we're
gonna do is we're gonna do this clear contents, which it does.
We're going to add a formula to A4.
We're gonna copy the formula.
And then I could go, hm, I wanna see something else happen.
Well, actually, you know what?
Let's paste the values again.
Here we go.
So we pasted it as February 28.
Now, what's interesting about playing around in this area,
is that i'm not bound to be working up and down the stack in a normal method.
I can look at this and say, you know what, I want to go see that again.
I am going to go back into this formulaR1C1, so
just drag the yellow arrow back up.
And at this point, what i'm going to do is I'm going to rewrite this guy again.
Which doesn't change the formula,
because it's pointing to the cell above in order to actually do anything.
But now, I'm going to reexecute this line again, copy, and then when I paste it this
time, it actually advances it to March, because I've stepped out of sequence.
So this is what's kind of interesting with the way this works,
is that we can actually step up and backwards and forwards.
And I could say, you know what?
Maybe I don't wanna execute this line for whatever reason.
So I'm just gonna drag down and skip it, and move on to the next line here.
I didn't execute this this time, and now we'll say A6 select.
So you'll notice that I didn't clear the contents of cell A4, it's still here,
and now we could say, end sub, when we actually run that, it steps out and
is no longer in the actual edit or no longer in run mode.
Now something that's really important here.
You guys may recall that I said this before, but I look at this and go,
that's a bit of a disaster, I'd really like to undo it.
But look at my undo stack, totally grayed out.
So in this particular case here, this is where it's really,
really useful to be able to say let's go File > Close.
Nope, Don't Save that one.
There we go. Now notice everything's going with it.
All the workbooks are closing in the Visual Basic Editor.
And now I can go and say, let's go back to Debugging Basics.
We'll bring this guy back up, and here we go.
Our code is good to go.
Notice all of my window frames stay the same as what I had them set before.
So this is really a useful tool, rather than just hitting run,
which will run through everything, we can actually step through individual
components of this particular code to actually let it go.
You can also, for reference, run the entire macro from this area
by just clicking on this little green guy or pressing F5
for that matter, would also allow you to do it.
So if I press run, it will run the entire thing.
You can see it just did its job, or I can step through, or
I can press the F8 key, which will also allow me to go and
execute this line by line to actually see what's happening.
So, this could be a very, very useful tool for going through and
trying to figure out why is your Macro is doing what you told it to,
instead of what you wanted it to do.
Because it always does what you told it to, whether or
not that's what we wanted to do or not.
So, number one secret in programming.
Anyway.
Big key I want you to remember, when a row is highlighted in yellow, it's active.
So if you want to actually get out of it, you either need to run it through the end.
Which we can do, by the way,
by saying Step, Step, Step if I wanna see it run the rest of the way, continue.
Or I could say Step, Step, Step and
I can actually stop the macro from running as well, okay?
So some different ways to actually use that particular feature.