FryGirl
Well-known Member
- Joined
- Nov 11, 2008
- Messages
- 1,368
- Office Version
- 365
- 2016
- Platform
- Windows
I need to loop thru a specified number of worksheets and run a sub. I would like to keep the two subs separately since it actually has two purposes.
Basically, If Sheet5.Range("B1").value = "Prod" then I need to loop thru the 12 sheets, but if not, then I need to just run the Sub RunMe on Sheet3.
I've crafted an initial sub, but not sure how to pass between the two.
Basically, If Sheet5.Range("B1").value = "Prod" then I need to loop thru the 12 sheets, but if not, then I need to just run the Sub RunMe on Sheet3.
I've crafted an initial sub, but not sure how to pass between the two.
Code:
[FONT=Times New Roman][COLOR=#000000]Sub FillEachWs()[/COLOR][/FONT]
[COLOR=#000000][FONT=Times New Roman] Dim i As Long[/FONT][/COLOR]
[COLOR=#000000][FONT=Times New Roman] For i = 1 To 12[/FONT][/COLOR]
[COLOR=#000000][FONT=Times New Roman] If Sheet5.Range("B1").Value ="Prod" Then[/FONT][/COLOR]
[COLOR=#000000][FONT=Times New Roman] With Sheets(CStr(i))[/FONT][/COLOR]
[COLOR=#000000][FONT=Times New Roman] Call RunMe[/FONT][/COLOR]
[COLOR=#000000][FONT=Times New Roman] End With[/FONT][/COLOR]
[COLOR=#000000][FONT=Times New Roman] Else[/FONT][/COLOR]
[COLOR=#000000][FONT=Times New Roman] Next i[/FONT][/COLOR]
[FONT=Times New Roman][COLOR=#000000]End Sub[/COLOR][/FONT]
Code:
[FONT=Times New Roman][COLOR=#000000]Sub RunMe()[/COLOR][/FONT]
[COLOR=#000000][FONT=Times New Roman] Sheet3.Range("AU1").Value ="Check"[/FONT][/COLOR]
[FONT=Times New Roman][COLOR=#000000]End Sub[/COLOR][/FONT]
Last edited: