Let's say I have 10 sheets in an Excel workbook and Sheet2 through Sheet10 are uniquely formatted.
Let's say I recorded 9 unique macros.
Sheet1 is a central location to house nine buttons. One button for each recorded macro so that when the user goes to sheet 1 and clicks a button called "sheet 2" it will run the macro for sheet 2 against sheet 2, even if the user is on the active sheet 1. Or if the user clicks the button called "sheet 10" it runs the recorded macro for sheet 10 against sheet 10, etc.
Here is a simplified version of one of the macros.
Sub Sheet2()
'
' Sheet2 Macro
'
'
End Sub
Sub Sheet2Macro()
'
' Sheet2Macro Macro
'
'
Range("A2:C2").Select
Selection.AutoFill Destination:=Range("A2:C10"), Type:=xlFillDefault
Range("A2:C10").Select
End Sub
I found this code online that I added at the top and it runs to success but only on the active sheet:
Dim WkSheets As Variant, SheetName As Variant, ws As Worksheet
'** SET The Sheet Names - MUST Reflect Each Sheet Name Exactly!
WkSheets = Array("Sheet 2")
For Each SheetName In WkSheets
'MsgBox SheetName
For Each ws In ActiveWorkbook.Worksheets
If ws.Name = SheetName Then
'Your Code Here