Loop through Array of Sheets, run code

willastrowalker

New Member
Joined
Aug 28, 2015
Messages
9
I've got this code, right, and I'm trying to have it run on speicific sheets only (that don't change). The code is just running 6 times on the same sheet.

The code is supposed to delete current outline, outline the page based on values in Column A/Row 1, and then show the outline to level 3 (out of 4).

Excel Formula:
Sub Allsheets()

    Dim ws As Variant
    Dim Matrixes As Variant

   Matrixes = Array("Net (Receivables - Payables)", "Gross Due From (Payables)", "Gross Due To (Receivables)", "Receivables Net", "Payables Net", "Gross Due From (Receivables)", "Gross Due To (Payables)")
   
              
    For Each ws In Matrixes
        
        Cells.ClearOutline
        OutlinePage
        ActiveSheet.Outline.ShowLevels ColumnLevels:=3
        ActiveSheet.Outline.ShowLevels RowLevels:=3
    
    Next ws

    
    Application.ScreenUpdating = True
    Application.Calculation = xlCalculationManual

End Sub
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Hi,

no other sheet is chosen in the code:
VBA Code:
Sub Allsheets_re()

  Dim ws As Worksheet
  Dim Matrixes As Variant
 
  Matrixes = Array("Net (Receivables - Payables)", "Gross Due From (Payables)", "Gross Due To (Receivables)", "Receivables Net", "Payables Net", "Gross Due From (Receivables)", "Gross Due To (Payables)")
   
  'runs in active workbook
  For Each ws In Worksheets(Matrixes)
    
    ws.Cells.ClearOutline
    'next codeline is not available in Excel20919?
    ws.OutlinePage
    ws.Outline.ShowLevels ColumnLevels:=3
    ws.Outline.ShowLevels RowLevels:=3

  Next ws

  Application.ScreenUpdating = True
  Application.Calculation = xlCalculationManual '???
End Sub
Ciao,
Holger
 
Upvote 0
Hi all,
an alternative solution
VBA Code:
Dim ws As Worksheet
                
    For Each ws In Sheets(Array("Net (Receivables - Payables)", "Gross Due From (Payables)", "Gross Due To (Receivables)", "Receivables Net", "Payables Net", "Gross Due From (Receivables)", "Gross Due To (Payables)"))
    
       'my code here
            
    Next ws

Code:
' also   Application.ScreenUpdating = True is never been set to False
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,843
Members
449,051
Latest member
excelquestion515

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