Home > Software design >  Loop through all Sheets in workbook
Loop through all Sheets in workbook

Time:06-19

I have an excel file with 100 sheets, all with the same layout, and I need to apply some formatting to all of these sheets.

What I need is a Macro that Loops through all Sheets of a workbook the same code.

I tried this one but is does NOT work

Dim ws As Worksheet 
For Each ws In ThisWorkbook.Worksheets
        Range("A1").Select
        Application.CutCopyMode = False
        ActiveCell.FormulaR1C1 = "Balance Sheet"         
        Range("Q1").Select
        Application.CutCopyMode = False
        ActiveCell.FormulaR1C1 = "Cash Flow"
Next ws
End Sub

Can you help me with this ? Thanks!!

CodePudding user response:

Replace that with:

Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
    ws.Range("A1").Value = "Balance Sheet"
    ws.Range("Q1").Value = "Cash Flow"
    Application.CutCopyMode = False
Next ws
  • Related