Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Multiple change events on same sheet

I'm sure this is an easy question. I already have a
Worksheet_Change(ByVal Target as Range) procedure for my "Sales"
worksheet. I need to add code to respond to some additional changes on
the sheet. How is that done? (I added the code in the same procedure,
but it doesn't work.)

Thanks.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Multiple change events on same sheet

Use Else, like this

Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range("H1:H10")) Is Nothing Then
With Target
'do your stuff
End With
ElseIf Not Intersect(Target, Me.Range("M5:M15")) Is Nothing Then
With Target
'do your stuff
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"JG Scott" wrote in message
ups.com...
I'm sure this is an easy question. I already have a
Worksheet_Change(ByVal Target as Range) procedure for my "Sales"
worksheet. I need to add code to respond to some additional changes on
the sheet. How is that done? (I added the code in the same procedure,
but it doesn't work.)

Thanks.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Multiple change events on same sheet

Add the code in the same procedure in a case statement as one way.

Private Sub Worksheet_Change(ByVal Target As Range)
Select Case Target.Address(0,0)
Case "A1"
' action to take if A1 is change
Case "B9","C5"
' action to take if B9 or C5 is changed
Case "F2"
' action to take if F2 is changed
End Select
End Sub

--
Regards,
Tom Ogilvy

"JG Scott" wrote in message
ups.com...
I'm sure this is an easy question. I already have a
Worksheet_Change(ByVal Target as Range) procedure for my "Sales"
worksheet. I need to add code to respond to some additional changes on
the sheet. How is that done? (I added the code in the same procedure,
but it doesn't work.)

Thanks.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Multiple change events on same sheet

Thanks. Very helpful.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,560
Default Multiple change events on same sheet

Thanks Bob...I was having the same issue with two change events and your
ELSEIF on the 2nd event got me what I needed!
Thanks much!

"Bob Phillips" wrote:

Use Else, like this

Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range("H1:H10")) Is Nothing Then
With Target
'do your stuff
End With
ElseIf Not Intersect(Target, Me.Range("M5:M15")) Is Nothing Then
With Target
'do your stuff
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"JG Scott" wrote in message
ups.com...
I'm sure this is an easy question. I already have a
Worksheet_Change(ByVal Target as Range) procedure for my "Sales"
worksheet. I need to add code to respond to some additional changes on
the sheet. How is that done? (I added the code in the same procedure,
but it doesn't work.)

Thanks.




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
Combine 2 worksheet change events nobbyknownowt Excel Discussion (Misc queries) 0 May 28th 10 10:49 AM
Cell change events Richard Excel Discussion (Misc queries) 2 May 16th 07 04:18 PM
Change events and linked cells Don Wiss Excel Programming 1 July 2nd 04 10:15 PM
msg box and or sheet events paul Excel Programming 3 March 4th 04 07:33 AM
Excel 97 - Inconsistent Change Events TightCode Excel Programming 0 July 31st 03 06:00 PM


All times are GMT +1. The time now is 07:14 AM.

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"