Consulting

Results 1 to 7 of 7

Thread: All VBA Worksheet_Change Events Not Working

  1. #1
    VBAX Mentor
    Joined
    Jan 2008
    Posts
    384
    Location

    All VBA Worksheet_Change Events Not Working

    Does anyone have any idea why suddenly, ALL of my Worksheet_Change events on my worksheets stopped working.
    This is some sample code that I had used. It worked once, but after I entered another value into another cell, it wouldn't fire the Worksheet_Change event code.
    Other projects with previously working code stopped working also.

    I tried it both with & without Application.EnableEvents = True

    Private Sub Worksheet_Change(ByVal Target As Range)
    
    Application.EnableEvents = True
    
        If Not Intersect(Target, Target.Worksheet.Range("A1:Z53")) Is Nothing Then
            MsgBox "A Cell changed"
        End If
    End Sub

  2. #2
    VBAX Mentor
    Joined
    Dec 2008
    Posts
    404
    Location
    Private Sub Worksheet_Change(ByVal Target As Range)
    
        If Not Intersect(Target, Target.Worksheet.Range("A1:Z53")) Is Nothing Then
          Application.EnableEvents = False 'If you turn off the events...
            MsgBox "A Cell changed"
          Application.EnableEvents = True '... you absolutely need to turn it on
        End If
    End Sub
    Artik

  3. #3
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Likely, you had an error and did not catch the error in the code and re-enable events again. Rather than closing and re-opening Excel, you can easily fix that by pasting this into your VBE's Immediate window and pressing Enter key.
    Application.EnableEvents = True
    Here is how I would do your Change event.
    Private Sub Worksheet_Change(ByVal Target As Range)  Dim r As Range
      
      Set r = Intersect(Target, Range("A1:Z53"))
      If r Is Nothing Then Exit Sub
      
      Application.EnableEvents = False
      MsgBox "A Cell changed in: " & r.Address
      Application.EnableEvents = True
    End Sub

  4. #4
    VBAX Mentor
    Joined
    Jan 2008
    Posts
    384
    Location
    Hi:
    I had previously tried both of your suggestions, along with some other ideas.
    I decided to take a fresh look at it today. Turned the system on and everything worked as it should.
    I never did figure out what was causing the problem. Still not sure.
    Thanks for both of your ideas.

  5. #5

    Lightbulb

    Quote Originally Posted by simora View Post
    Hi:
    I had previously tried both of your suggestions, along with some other ideas.
    I decided to take a fresh look at it today. Turned the system on and everything worked as it should.
    I never did figure out what was causing the problem. Still not sure.
    Thanks for both of your ideas.
    What's worked for me are these steps to recompile the vba project:
    1. Go to a blank excel worksheet. Disable macros without notification
    2. Disable trusted locations and trusted publishers.
    3. Go to the workbook in question and open VBA
    4. Click debug in the top ribbon and select "Compile VBA project"
    5. Save the project and close the workbook
    6. Reverse steps 1-4 and open the workbook.
    7. Everything should work as before.

  6. #6
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    Welcome to the board

    Please take a minute to review the FAQ link in my sig

    It's also a good to check the age of the post that you're replying to since many times the post is old and not an issue anymore; many times posters will not mark the issue [SOLVED]
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  7. #7

    Thumbs up

    Quote Originally Posted by Paul_Hossler View Post
    Welcome to the board

    Please take a minute to review the FAQ link in my sig

    It's also a good to check the age of the post that you're replying to since many times the post is old and not an issue anymore; many times posters will not mark the issue [SOLVED]
    Thanks Paul. I only responded, because although it was marked “SOLVED”, no solution had actually been offered that worked. In the future I will reply to more recent posts. Thanks!

Posting Permissions

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