Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
sgl sgl is offline
external usenet poster
 
Posts: 80
Default Skip ... Selection_Change Event

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Skip ... Selection_Change Event

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default Skip ... Selection_Change Event

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Skip ... Selection_Change Event

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Skip ... Selection_Change Event

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   Report Post  
Posted to microsoft.public.excel.programming
sgl sgl is offline
external usenet poster
 
Posts: 80
Default Skip ... Selection_Change Event

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Click event on menu item is lost after first time firing of the event [email protected] Excel Programming 1 April 2nd 07 01:25 PM
MsgBox in Enter event causes combobox not to run Change event Richard Excel Programming 0 March 6th 06 02:52 PM
How to trap delete row event and hide column event? Alan Excel Programming 3 April 26th 05 04:25 PM
user form-on open event? keydown event? FSt1[_3_] Excel Programming 2 August 5th 04 02:26 PM
OnTime event not firing in Workbook_Open event procedure GingerTommy Excel Programming 0 September 24th 03 03:18 PM


All times are GMT +1. The time now is 06:25 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"