ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   More then 1 Private Sub Worksheet_Change (https://www.excelbanter.com/excel-programming/436876-more-then-1-private-sub-worksheet_change.html)

FIRSTROUNDKO via OfficeKB.com

More then 1 Private Sub Worksheet_Change
 
HI,

can i have ore then 1 "Worksheet_Change" sub?

i.e

I havea sub, Private Sub Worksheet_Change

but, Private Sub Worksheet2_Change

will not work

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200912/1


Rick Rothstein

More then 1 Private Sub Worksheet_Change
 
No, you will just have to combine the code you want in your two Change
events into the Change event that VB provides. You can use If..Then blocks
to separate the functionality you wanted in your proposed separate Change
events.

--
Rick (MVP - Excel)


"FIRSTROUNDKO via OfficeKB.com" <u15639@uwe wrote in message
news:9ff261acc54dc@uwe...
HI,

can i have ore then 1 "Worksheet_Change" sub?

i.e

I havea sub, Private Sub Worksheet_Change

but, Private Sub Worksheet2_Change

will not work

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200912/1



Don Guillett

More then 1 Private Sub Worksheet_Change
 
No. but you can combine. As ALWAYS, post your code for comments.


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"FIRSTROUNDKO via OfficeKB.com" <u15639@uwe wrote in message
news:9ff261acc54dc@uwe...
HI,

can i have ore then 1 "Worksheet_Change" sub?

i.e

I havea sub, Private Sub Worksheet_Change

but, Private Sub Worksheet2_Change

will not work

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200912/1



JLGWhiz[_2_]

More then 1 Private Sub Worksheet_Change
 
Not fot the same sheet. However, you can have the worksheet change do more
than one thing by using If...Then statements. For example:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim sh As Worksheet
Set sh = ActiveSheet
If sh.Range("A1").Value 0 Then
'Do one thing
End If
If sh.Target.Value = "Do Something" Then
'Do another
End If
If Not Intersect(sh.Selection, Target) Is Nothing Then
"Do somethiing else
End If
End Sub

Only when the If statement is true will the code execute a command to do
something. If none of them are true then it executes no commands. If all
of them are true it executes all three commands.





"FIRSTROUNDKO via OfficeKB.com" <u15639@uwe wrote in message
news:9ff261acc54dc@uwe...
HI,

can i have ore then 1 "Worksheet_Change" sub?

i.e

I havea sub, Private Sub Worksheet_Change

but, Private Sub Worksheet2_Change

will not work

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200912/1





All times are GMT +1. The time now is 12:29 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com