+ Reply to Thread
Results 1 to 4 of 4

WorkSheet Change Event Handler error.

  1. #1
    Registered User
    Join Date
    01-13-2024
    Location
    Canada
    MS-Off Ver
    Office365
    Posts
    2

    Question WorkSheet Change Event Handler error.

    Hello,

    I am fairly new to VBA. Can someone confirm if I am doing something wrong with my code to get errors or if there is a better method?
    I am getting Out of Stack error and runtime error Worksheet Event Handler.
    I have a couple of cells that I want to track changes to trigger a value change to "Please Select...". These cells are droplist.
    For one of these dropdown lists, Range("B2") I want to see if it's a certain value if so then change the value of this other dropdown list Range("B14").

    Thanks in advance.
    Please Login or Register  to view this content.
    Last edited by jetguy; 01-14-2024 at 02:32 PM.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: WorkSheet Change Event Handler error.

    When you have this event handler, it is called by the system every time there is a change in the sheet. Your Sub changes the sheet itself. So when it changes the sheet, it gets called. Then it changes the sheet again, and gets called again. Each time it gets called, a new copy of the Sub is loaded onto the call stack. This goes on until the stack space is exhausted and you get a runtime error.

    At the beginning of your sub add
    Please Login or Register  to view this content.
    to prevent it from being called when it makes changes. Then at the end, add
    Please Login or Register  to view this content.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hello, try this !


    Quote Originally Posted by jetguy View Post
    if I am doing something wrong with my code to get errors
    Yes, bad Or syntax like bad logic as well !

    So correcting the logic, the syntax and removing the useless :

    PHP Code: 
    Private Sub Worksheet_Change(ByVal Target As Range)
            Const 
    "Please Select..."
            
    Application.EnableEvents False
       With Target
        
    If .Address "$B$1" Then
            
    [B2] = C
        
    ElseIf .Address "$B$2" Then
            
    [B3,B14,B17] = C
            
    If .Value 305 Or .Value 320 Or .Value 340 Or .Value 704 Then [B14] = "Material type1 or run new Macro event"
        
    End If
       
    End With
            Application
    .EnableEvents True
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !

  4. #4
    Registered User
    Join Date
    01-13-2024
    Location
    Canada
    MS-Off Ver
    Office365
    Posts
    2

    Re: WorkSheet Change Event Handler error.

    Thanks. I didn't realize it was doing that.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Runtime Error 28 - Out of Stack Space
    By jynxy in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 10-03-2023, 10:39 AM
  2. [SOLVED] Runtime error 28 Call Stack
    By anrichards22 in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 09-18-2017, 11:37 AM
  3. [SOLVED] Worksheet Change Event Causing Runtime Error 9
    By phelbin in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-13-2017, 03:59 PM
  4. [SOLVED] Runtime error '28'..... out of stack space solution!!
    By meus in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-12-2015, 05:58 AM
  5. How to change an event handler on error
    By alanb1976 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-08-2012, 08:07 AM
  6. runtime error, isempty, worksheet change event
    By Code Flunkie in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-28-2011, 05:17 PM
  7. [SOLVED] Run-time error '424' in VBA event handler on XL shutdown
    By Mike Jones in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-06-2005, 03:06 PM

Tags for this Thread

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