Run Macro on multiple worksheets within an excel file
Hello,
I am trying to create a macro to run on all worksheets within a tab. So far it is only running on one worksheet and it does not work on other. Can someone please assist me. Below is the code I used. Thank you
Code:
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
If ws.Name <> "Sheet1" Or ws.Name <> "Sheet2" Then
Columns("F:H").Select
Range("H1").Activate
Selection.EntireColumn.Hidden = True
End If
Next ws.Activate
End Sub
Re: Run Macro on multiple worksheets within an excel file
Welcome to the forums biyi11 :wave:
Is this wihat you are trying?
Code:
Sub Sample()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
If ws.Name <> "Sheet1" Or ws.Name <> "Sheet2" Then
ws.Columns("F:H").EntireColumn.Hidden = True
End If
Next
End Sub
Re: Run Macro on multiple worksheets within an excel file
Yes, but it seems not be working on all the tabs in the excel tab. Do I need an activate all worksheets statement included.
Quote:
Originally Posted by
koolsid
Welcome to the forums biyi11 :wave:
Is this wihat you are trying?
Code:
Sub Sample()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
If ws.Name <> "Sheet1" Or ws.Name <> "Sheet2" Then
ws.Columns("F:H").EntireColumn.Hidden = True
End If
End Sub
End Sub
Re: Run Macro on multiple worksheets within an excel file
Your first End Sub should be a next statement
Re: Run Macro on multiple worksheets within an excel file
Thanks kiwi. typo fixed.
Try it now biyi11