View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein Rick Rothstein is offline
external usenet poster
 
Posts: 5,934
Default Run VBA code only worksheet change, but don't trigger worksheet_change event based on what the code does

You would use the EnableEvents property of the Application object. Here is
one of the many way to structure it...

Private Sub Worksheet_Change(ByVal Target As Range)
If <Your_Test_Condition = True Then
On Error GoTo CleanUp
Application.EnableEvents = False
'
' <<Your code goes here
'
End If
CleanUp
Application.EnableEvents = True
End Sub

Note: The On Error trap is needed in case your code errors out... if you
don't turn the EnableEvents back on, it remains off for other macros that
may be executed afterwards.

--
Rick (MVP - Excel)


"ker_01" wrote in message
...
I have two cells with data validation (each using a named range/list that
brings in data from another sheet).

When one changes, it runs through my code and works just fine.

When the other data validation changes, one of the things I have to do is
re-set the other data validation cell to the default value. This part is
working fine, except that it triggers the worksheet_change event to run a
second time.

Is there an elegant way to catch/ignore the worksheet_change event when
changes are caused by code instead of user interaction?

Thanks,
Keith