+ Reply to Thread
Results 1 to 7 of 7

Prevent private sub macro from running

  1. #1
    Forum Contributor
    Join Date
    09-30-2008
    Location
    Eau Claire, WI
    Posts
    184

    Prevent private sub macro from running

    I need a line of code so that when I hit commandbutton2, the Private Sub Worksheet_Change(ByVal Target As Range) event macro on the same page DOESN'T run. The button clears certain lines, and when it runs the change event it ends up in an error, and I don't need it to run when hitting the commandbutton. Thanks!
    Last edited by jman0707; 11-15-2008 at 01:35 AM.

  2. #2
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127
    One option is to have the command button add text to a random cell when clicked (for example, add an "x" to cell Z1. Then you can add a test to the Worksheet_Change Event.

    A quick example:

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    09-30-2008
    Location
    Eau Claire, WI
    Posts
    184
    Thanks! 2 quick questions. i've never had a button put text in a cell, what syntax does that use? And once I push the button, won't the text stay in the cell and then every time I change something in the worksheet it won't run the worksheet_change event? Or does it somehow test it, then I can get it to delete?

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492
    Please Login or Register  to view this content.
    Then BigBas' code adjusts to watch AA1 as so:
    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  5. #5
    Forum Contributor
    Join Date
    09-30-2008
    Location
    Eau Claire, WI
    Posts
    184
    It can't be an off/on sort of thing, I need it the commandbutton to clear certain rows without triggering worksheet_change, then allow the worksheet_change event to be immediately active again. Here's what I put in the commandbutton code:

    Please Login or Register  to view this content.
    And this in the workshee_change event right in the beginning:

    Please Login or Register  to view this content.
    But it's still not quite working. Any ideas?
    Last edited by jman0707; 11-15-2008 at 01:16 AM.

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492
    You haven't told us what you're deleting, so you'll have to edit the "clear" event in this code to delete what you want, but this commandbutton macro will work:
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    09-30-2008
    Location
    Eau Claire, WI
    Posts
    184
    Oh, Ok perfect! I think all I needed was the enableevents to be false so nothing else would run. Thanks!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1