Performing actions on multiple tabs with VBA

njbeancounter

Board Regular
Joined
Oct 7, 2002
Messages
158
Hello...

My workbook contains numerous tabs, but I only want to perform the following actions on 5 of them.

Each tab has general ledger information for individual companies, so the rows all contain the same account numbers, and the columns all contain the same months.

I want to create an array (maybe) for the five worksheets (companies) and then in each sheet, hide rows 3 thru 141.

Once I get this to work, there is more I want to do, but this is the basis for the rest of what I want to do.

Thanks
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
You can hide the rows like
VBA Code:
Sub njbeancounter()
   Dim Ws As Worksheet
   
   For Each Ws In Worksheets
      Select Case Ws.Name
         Case "Sheet1", "Sheet2", "Sheet3"
            Ws.Rows("3:141").Hidden = True
      End Select
   Next Ws
End Sub
 
Upvote 0
Solution
Here is a little example of how you can store sheet names in an array and loop through them.
VBA Code:
Sub TestMacro()

    Dim sh
    Dim i As Long
    
    sh = Array("Sheet1", "Sheet2", "Sheet4")
    
    For i = LBound(sh) To UBound(sh)
        'Put the word "Test" in cell A1
        Sheets(sh(i)).Range("A1") = "Test"
    Next i
    
End Sub
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,534
Messages
6,120,080
Members
448,943
Latest member
sharmarick

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