Let's say I have 10 sheets in an Excel workbook and Sheet2 through Sheet10 are all unique in how they need to be formatted. Let's say I recorded 9 unique macros for each and I want a central location to house all the buttons (in Sheet1), 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 recorded 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. Is this possible?
One of the comments mentioned to include one of the recorded macros, here is an oversimplified 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 also found this bit of code online that I added at the top and it runs to success but somehow it only runs 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