How to set macro for one specific sheets?

alz

Board Regular
Joined
Jul 17, 2020
Messages
130
Office Version
  1. 2019
Platform
  1. Windows
How to set macro for one specific sheets?
Example. Sheets name : A001, A002,A003
I want to run my vba code to run when active sheet is A001.
Please advise .Thanks
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Hi Alz,
1. Goto VBA editor and double click on sheet A001 in project explorer.
2. In Code window, select worksheet in left drop down and Activate in right drop down.
3. Writer your macro in created event handler.

(See attached image)
 

Attachments

  • MacroForWorksheetActivateEvent.PNG
    MacroForWorksheetActivateEvent.PNG
    134.5 KB · Views: 10
  • Like
Reactions: alz
Upvote 0
Solution
If you want a code to run only if active worksheet name is "A001" then try:
If you want to run when A001 is activated then use the code above.
VBA Code:
Sub Test()
If ActiveSheet.name<>"A001" Then Exit Sub
Msgbox "Hello world! The active worksheet is named A001!"
End sub
 
  • Like
Reactions: alz
Upvote 0
If you want a code to run only if active worksheet name is "A001" then try:
If you want to run when A001 is activated then use the code above.
VBA Code:
Sub Test()
If ActiveSheet.name<>"A001" Then Exit Sub
Msgbox "Hello world! The active worksheet is named A001!"
End sub
Thanks :)
 
Upvote 0

Forum statistics

Threads
1,214,987
Messages
6,122,613
Members
449,090
Latest member
vivek chauhan

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top