Share via

breakpoints not working

Anonymous
2011-10-24T01:06:12+00:00

I have a macro (Worksheet_Change, one of the built-in ones) in which the breakpoints are not working. I know the code is running because it's only one line, a msgbox command, and the text displays as expected. However, if I put a breakpoint on the same line, the breakpoint never triggers.

Breakpoints DO work in other macros. I've tried rebuilding the workbook from scratch (copying and pasting the data only), but it still fails. I tried removing the offending procedure (Worksheet_Change) and recreating it, and it still fails, even with only one line. The line executes perfectly, but the breakpoint never triggers.

Doing exactly the same thing in another workbook works perfectly. So, something is set wrongly on this workbook.

I've seen a lot of forum posts with the precise problem I am having. The ones that have solutions all say to check or uncheck "Special Keys" under Tools | Startup Options. Well, I'm on Office 2010, and 2010 doesn't seem to have that option. Nor is there any reference to it in the "what happened to" help pages.

One last thing: If I add the same code to the procedure Worksheet_SelectionChange (same parameters, etc), it works perfectly.

Any ideas?

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

4 answers

Sort by: Most helpful
  1. Andreas Killer 144.1K Reputation points Volunteer Moderator
    2011-10-25T07:05:50+00:00

    Curious, can you send me that file? (email address is in my profile)

    Andreas.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2011-10-24T19:55:11+00:00

    Both compile on demand and background compile are checked.

    Besides, it can't be that, or it would fail on both macros. Remember: It only fails on Worksheet_Change, but works on Worksheet_SelectionChange. And, it follows the macro NAME when I remove the word "Selection" from one and put it into the other.

    Also remember that the code works perfectly. Here's the procedure:

    Sub Worksheet_Change(ByVal Target As Range)

       msgbox("test")

    End Sub

    When I run this, the code runs, and I see the word "test" in a message. But, if I have a breakpoint on that line, it does not break. It still runs and I still see "test", but the breakpoint is ignored.

    If I swap the procedure name to

    Sub Worksheet_SelectionChange(ByVal Target As Range)

       msgbox("test")

    End Sub

    then it works, and the other procedure fails (the one that used to be called Worksheet_SelectionChange and is now called Worksheet_Change).

    Was this answer helpful?

    0 comments No comments
  3. Andreas Killer 144.1K Reputation points Volunteer Moderator
    2011-10-24T10:20:32+00:00

    I guess your compiler doesn't compile the project after a change automatically, check the options in the general tab:

    http://www.fmsinc.com/tpapers/vbacode/debug.asp#BasicErrorHandling

    Andreas.

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2011-10-24T01:34:02+00:00

    It's even worse than I thought. I tried cutting and pasting the word "Selection" from the title of "Worksheet_SelectionChange" (the working one) and putting the "Selection" into "Worksheet_Change". So the two procedures should now be switched.

    Sure enough, the problem followed the newly named Worksheet_Change. Switch them back, and the problem returns to the original macro. So, this HAS TO be something in the guts of vba and how it handles this particular program.

    Was this answer helpful?

    0 comments No comments