Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi all your assistance please ...,
I have a Selection_Change event in a particular wks. I also have several Macros for expanding/hiding rows and columns in the same wks. How can I 'SKIP' the Selection_Change event when I trigger one of these macros but have the Selection_Change event work correctly if the Macro is NOT triggered. Many thanks in advance/sgl |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
In general, what yuo'd want to do si set up a global variable which
flags that the macro was called and set that within the macro code e.g. gbCalledFromMacro = True). Now, in the code behind your Slectoin_Change() event, add code like the following: Selectcion_change() If (gbCalledFromMacro = True) Then gbCalledFromMacro = False Exit sub End if' ' implied else ' Your normal goes code End sub HTH / Tyla / On May 2, 8:12 am, sgl wrote: Hi all your assistance please ..., I have a Selection_Change event in a particular wks. I also have several Macros for expanding/hiding rows and columns in the same wks. How can I 'SKIP' the Selection_Change event when I trigger one of these macros but have the Selection_Change event work correctly if the Macro is NOT triggered. Many thanks in advance/sgl |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Sgl,
You usually don't have to select cells when working with them in code. But if you have to do the select, one way to avoid firing the SelectionChange event is to disable/enable events: Application.EnableEvents = False Range("A4").Select Application.EnableEvents = True Another way is to declare a module level variable. For example: Dim bFireSelect As Boolean Private Sub Worksheet_SelectionChange(ByVal Target As Range) If bFireSelect Then Exit Sub 'your code here End Sub Sub testSelect() bFireSelect = True Range("A3").Select bFireSelect = False End Sub -- Hope that helps. Vergel Adriano "sgl" wrote: Hi all your assistance please ..., I have a Selection_Change event in a particular wks. I also have several Macros for expanding/hiding rows and columns in the same wks. How can I 'SKIP' the Selection_Change event when I trigger one of these macros but have the Selection_Change event work correctly if the Macro is NOT triggered. Many thanks in advance/sgl |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
The best way to skip the Selection_Change event is to avoid making
selections in your macros. They're almost never necessary. Code that works with range objects directly is almost always faster, smaller and easier to maintain months down the road. If you're not sure how to do that, post a reply with the relevant code. Another way to do it is to wrap the guts of your macros with: Public Sub foo() On Error GoTo ErrorHandler Application.EnableEvents = False 'your code here ErrorHandler: Application.EnableEvents = True End Sub In article , sgl wrote: Hi all your assistance please ..., I have a Selection_Change event in a particular wks. I also have several Macros for expanding/hiding rows and columns in the same wks. How can I 'SKIP' the Selection_Change event when I trigger one of these macros but have the Selection_Change event work correctly if the Macro is NOT triggered. Many thanks in advance/sgl |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Disable events in your code, do the work, then turn on that even handling:
Application.enableevents = false 'your code to add/delete/hide rows or columns application.enableevents = true sgl wrote: Hi all your assistance please ..., I have a Selection_Change event in a particular wks. I also have several Macros for expanding/hiding rows and columns in the same wks. How can I 'SKIP' the Selection_Change event when I trigger one of these macros but have the Selection_Change event work correctly if the Macro is NOT triggered. Many thanks in advance/sgl -- Dave Peterson |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
You are all fantastic. Never had so many positive replies so fast. All of
them worked.Thank you all/sgl "Dave Peterson" wrote: Disable events in your code, do the work, then turn on that even handling: Application.enableevents = false 'your code to add/delete/hide rows or columns application.enableevents = true sgl wrote: Hi all your assistance please ..., I have a Selection_Change event in a particular wks. I also have several Macros for expanding/hiding rows and columns in the same wks. How can I 'SKIP' the Selection_Change event when I trigger one of these macros but have the Selection_Change event work correctly if the Macro is NOT triggered. Many thanks in advance/sgl -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Click event on menu item is lost after first time firing of the event | Excel Programming | |||
MsgBox in Enter event causes combobox not to run Change event | Excel Programming | |||
How to trap delete row event and hide column event? | Excel Programming | |||
user form-on open event? keydown event? | Excel Programming | |||
OnTime event not firing in Workbook_Open event procedure | Excel Programming |