ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   activate macro only in sheet2 (https://www.excelbanter.com/excel-worksheet-functions/78573-activate-macro-only-sheet2.html)

Narkom

activate macro only in sheet2
 

How do I activte a macro only for sheet2?


--
Narkom
------------------------------------------------------------------------
Narkom's Profile: http://www.excelforum.com/member.php...o&userid=32642
View this thread: http://www.excelforum.com/showthread...hreadid=524554


Otto Moehrbach

activate macro only in sheet2
 
I don't know how you want to activate the macro, but if you want it to work
only on Sheet2, use a line something like:
If ActiveSheet.Name<"Sheet2" Then Exit Sub
If you want it to work with only Sheet2 whether or not it is the active
sheet use something like:
With Sheets("Sheet2")
'Your code goes here
End With
HTH Otto
"Narkom" wrote in
message ...

How do I activte a macro only for sheet2?


--
Narkom
------------------------------------------------------------------------
Narkom's Profile:
http://www.excelforum.com/member.php...o&userid=32642
View this thread: http://www.excelforum.com/showthread...hreadid=524554




Richard Buttrey

activate macro only in sheet2
 
On Mon, 20 Mar 2006 14:40:46 -0600, Narkom
wrote:


How do I activte a macro only for sheet2?


If Sheet2 is the Active Sheet when the macro runs, then wrap your
macro code in an IF..Then test

If ActiveSheet.Name="Sheet2 Then
YourCode...
End If

If you are looping through various sheets without them becoming
active, then the same logic applies, just test for the sheet name at
the start of your code.


HTH
__
Richard Buttrey
Grappenhall, Cheshire, UK
__________________________

Narkom

activate macro only in sheet2
 

That was it!
Finally i got some light :)
Thank you both


--
Narkom
------------------------------------------------------------------------
Narkom's Profile: http://www.excelforum.com/member.php...o&userid=32642
View this thread: http://www.excelforum.com/showthread...hreadid=524554



All times are GMT +1. The time now is 11:15 PM.

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