Trapping a Error in a Macro

I have a very complex WB with a Macro that clears all of the input fields within the WB as well as hides all of the Tabs.  I have received an error after I installed a macro that runs in one of the Tabs that gets the input fields cleared and then hidden.  I've tried to comment out and isolate the problem but still cannot find it.

The line of code that gets flagged each time is:

    If Not Intersect(ActiveCell, Range("F2")) Is Nothing Then

The code above it is:

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim rFind As Range, rStep As Range
    Dim sSheet As String, sRange As String
    Dim strNF As String
    Dim strCell As String
    Dim wsCurrency As Worksheet
    Set wsCurrency = Worksheets("Currency")
   
    If Target.Cells.Count > 1 Then Exit Sub
    If Not Intersect(ActiveCell, Range("F2")) Is Nothing Then

Here is my question:  How do I "step" through the macro in order to isolate the problem?

Thank you in advance.

B.
Bright01Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mvidasCommented:
Hi B,

Above the line you want to step through, enter the command "Stop".
Alternatively, you could also press F9 on the line and it will highlight in a dark red color, that tells the program to stop at that line during execution. You then press F8 to go line-by-line.

For what it's worth, change your bad line from ActiveCell to Target, in case multiple cells are being changed.

Matt
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Bright01Author Commented:
Wow!  Taught me a lesson AND fixed my problem......... you are good!

Thanks so much.  

B.
0
Martin LissOlder than dirtCommented:
If you want to learn more about debugging take a look at this article of mine. Don't be put off because it says VB6 since most of it applies to VBA.
0
Bright01Author Commented:
Great Marty!  Thanks a lot.  I'll take a look.

One Question for you, by changing the line from "Activecell" to "Target", should I expect any problems or challenges?  What does that actually do?
0
mvidasCommented:
One Question for you, by changing the line from "Activecell" to "Target", should I expect any problems or challenges?  What does that actually do?
That depends on what the macro does I guess. What the line is doing is making sure the cell you want got changed.

For example, highlight the range D1:G3. If you press Delete, it will trigger the worksheet_change event. And in doing so, your cell F2 (that you're checking in the code) will be cleared. However, since D1 would be the ActiveCell, intersecting ActiveCell with F2 results in nothing, and your code would not run. In this case, ActiveCell would refer to D1, and Target would refer to D1:G3.

Future problems/challenges depend on what exactly your code is doing, and is hard to say either way. It is possible more issues arise (if you refer to ActiveCell more, or your code only interacts with one cell), but its hard to say without seeing it. Feel free to post it, and I can give it a look.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Applications

From novice to tech pro — start learning today.