+ Reply to Thread
Results 1 to 6 of 6

Worksheet Events Not Working Consistenly

Hybrid View

incjourn Worksheet Events Not Working... 01-07-2009, 07:08 AM
mudraker Did you copy & paste the code... 01-07-2009, 07:27 AM
royUK You also need to add On Error... 01-07-2009, 07:35 AM
romperstomper If you Debug and press Stop,... 01-07-2009, 08:02 AM
incjourn ? 01-08-2009, 05:50 AM
romperstomper Yeah you can just type: ... 01-08-2009, 05:57 AM
  1. #1
    Registered User
    Join Date
    03-16-2004
    Location
    UK
    MS-Off Ver
    2003
    Posts
    85

    Worksheet Events Not Working Consistenly

    All,

    I have been working with Worksheet_SelectionChange and Worksheet_Change events. They start of working and then they stop, sometimes after a de-bug and sometime after a change on the worksheet. If I save and close the workbook and open it again it is fine. Can anybody tell me what is happening and suggest a fix?

    An example of my code...

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    
    On Error Goto Error Handler
    
    NmRng = Target.Name.Name
     Application.EnableEvents = False
            
            If Left(NmRng, 3) = "INP" Then
                NmVal = Target.Value
                NewVal = InputBox("Enter New Value", "Updtate Parameter) 
            End If
            
    ErrorHandler:
            Application.EnableEvents = True
    End Sub
    Phil

  2. #2
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    Did you copy & paste the code into your posting or type it in

    Your posted code has a couple of errors init that will cause it to error & not run at all

    On Error Goto Error Handler
    should be
    On Error Goto ErrorHandler
    NewVal = InputBox("Enter New Value", "Updtate Parameter)
    should be probally be
    NewVal = InputBox("Enter New Value", "Update Parameter")
    Not shure what you are trying to do with using Name twice
    NmRng = Target.Name.Name
    Please Read Forum Rules Before Posting
    Wrap VBA code by selecting the code and clicking the # icon or Read This
    How To Cross Post politely

    Top Excel links for beginners to Experts

    If you are pleased with a member's answer then use the Scales icon to rate it
    If my reply has assisted or failed to assist you I welcome your Feedback.

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    You also need to add On Error GoTo 0 at the end to return error handling to Excel
    Last edited by royUK; 01-07-2009 at 07:40 AM.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,978
    If you Debug and press Stop, your code will not run to the end and events will be disabled. Restarting Excel will reset that.
    You would only use On Error Goto 0 if you wanted to disable all error handlers, which is presumably not the case here.

  5. #5
    Registered User
    Join Date
    03-16-2004
    Location
    UK
    MS-Off Ver
    2003
    Posts
    85

    ?

    Thaks that's helpful.
    Is there any other way to reset the events without closing and opening the workbook?

  6. #6
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,978
    Yeah you can just type:
    Application.EnableEvents = True
    in the Immediate Window and press enter. I have two one-line subs for turning events on and off when I'm debugging.

+ 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