Macro to Run in One Worksheet

Papi

Well-known Member
Joined
May 22, 2007
Messages
1,592
Can a person run a macro that will only run in one worksheet and not the other worksheets in the same workbook?
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Hi,

Depending what you want to do or how it works the code you have, an option would be.

Code:
Sub MyMacro()
If ActiveSheet.Name = "Sheet1" Then
[COLOR=Green]    'My code[/COLOR]
Else
    Exit Sub
End If
End Sub
Hope this helps.

If not is what you want, please give more details and if it's possible what does the code in that sheet.

Regards.
 
Upvote 0
There are so many macros in the workbook that I am running out of shortcut letters. So if I have a macro that uses Ctrl + Shift + R for inserting a row in Sheet1 and in Sheet2 I want to use Ctrl + Shift + R to perform something different. Does this make sense?
 
Upvote 0
Do you want to do Ctrl + Shift + R to execute Macro1 in Sheet1 and in Sheet2 and at the same time you
want to execute a macro only in Sheet1 or Sheet2 using the same shortcut?

I don´t get it how to do that. Maybe if that shortcut is linked to Macro1 and if you don't want to execute
the macro for a especific sheet or do something different with the same macro, within the macro you need
to add some condition depending what you looking for.

Sorry, I think is not the help you want, only I'm not clear enough.

Regards
 
Upvote 0
The macros would never run the same time. All I would like to do is know that I can run a different macro with the same shortcut. Say I want to insert a ROW in Sheet1 using Ctrl + Shift + R to do that. Then to be able to use the same shortcut in another worksheet i.e. possibly Ctrl + Shift + R to REMOVE a row in Sheet2 and so forth.
 
Upvote 0
I think assigning 2 macros with the same shortcut will just run the first uisng alphabetical order.

Use the CTRL+Shift+R to run a macro that calls other macros?

If Activesheet is sheet1 Call Macro 1
If Activesheet is sheet2 Call Macro2

Or as the previous poster suggested in the same macro.

If sheet1 then

Do stuff

If sheet2 do something different.
 
Upvote 0
Can a person run a macro that will only run in one worksheet and not the other worksheets in the same workbook?

Yes just put the code in sheet1 or sheet2 instead of putting it in the module...
Hint: Place your code in Worksheet.activate then only when that sheet activate only then your code will work
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,726
Members
452,939
Latest member
WCrawford

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