Loop through 4 named worksheets in a workbook

Brian F

Active Member
Joined
Aug 31, 2009
Messages
256
Windows 7, Excel 2010; I have a workbook with four named worksheets ("Sheet_A","Sheet_B","Sheet_C" and "Sheet_D")
I want to loop through those for sheets and perform the same tasks in each sheet. Can someone tell me how to loop through each of these 4 sheet. Thank you in advance for any help offered.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Hi

You could use something like this:

Code:
Dim sht As Variant

For Each sht In Array("Sheet_A","Sheet_B","Sheet_C","Sheet_D")
   'now do stuff with each eg:
   Sheets(sht).ClearContents
Next sht
 
Upvote 0
Maybe try:
Code:
Dim iSheet as Worksheet
For Each iSheet in Sheets(Array("Sheet_A", "Sheet_B", "Sheet_C", "Sheet_D"))
  With iSheet
    MsgBox .Name 'replace with your code
  End With
Next iSheet
 
Last edited:
Upvote 0
Try:
Code:
Public Sub LoopThroSheets()
Dim ws As Worksheet
For Each ws In Sheets(Array("Sheet_A", "Sheet_B", "Sheet_C", "Sheet_D"))
    With ws
        'Write sheet specific code here.
    End With
Next ws
End Sub
 
Upvote 0

Forum statistics

Threads
1,226,730
Messages
6,192,708
Members
453,748
Latest member
akhtarf3

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