VBA: Hide Columns in multiple sheets using loop

unknownymous

Board Regular
Joined
Sep 19, 2017
Messages
249
Office Version
  1. 2016
Platform
  1. Windows
Hi All,

I'm currently looking for ways on how I can hide columns in multiple tabs sheets.

Hide Columns: A, C-E, H, K-P,V-Z
Sheets to loop: Sheet1, Sheet1 (2), Sheet1 (3), Sheet1 (4), Sheet1 (5) and so on (example Sheet1 (6)
Note: If sheet's doesn't exist, just skip.


Any help would be greatly appreciated!


Thank you!!!
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Do you want it to work on all sheets that start Sheet1?
 
Upvote 0
Upvote 0
Ok, how about
VBA Code:
Sub unknownymous()
   Dim ws As Worksheet
   
   For Each ws In Worksheets
      If ws.Name Like "Sheet1*" Then
         ws.Range("A:A,C:E,H:H,K:P,V:Z").EntireColumn.Hidden = True
      End If
   Next ws
End Sub
 
Upvote 0
Works perfectly! Thank you :)
Ok, how about
VBA Code:
Sub unknownymous()
   Dim ws As Worksheet
  
   For Each ws In Worksheets
      If ws.Name Like "Sheet1*" Then
         ws.Range("A:A,C:E,H:H,K:P,V:Z").EntireColumn.Hidden = True
      End If
   Next ws
End Sub

orks perfectly
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,148
Members
453,021
Latest member
Justyna P

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