VB Code -- Make this Concise

Desu Nota from Columbus

Well-known Member
Joined
Mar 17, 2011
Messages
556
I need columns S:U to be hidden for 7 sheets.

The sheet names are:
Line1
Line2
Line3
Line4
Line5
Line6
Line10

Is there any alternative, shorter way to accomplish the following (for each sheet):

Code:
Sheets("Line1").Select
Columns("S:U").Select
Selection.EntireColumn.Hidden = True
 

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.
Code:
Sub kpark91()
    Dim i As Integer
    For i = 1 To 6
        Sheets("Line" & i).Columns("S:U").EntireColumn.Hidden = True
    Next i    
    Sheets("Line10").Columns("S:U").EntireColumn.Hidden = True
End Sub
 
Upvote 0
Try:
Code:
For Each Sheet in Sheets(Array("Line1", "Line2", "Line3", "Line4", "Line5", "Line6", "Line10"))
    Columns("S:U").EntireColumn.Hidden = True
Next
 
Upvote 0
Code:
Sub kpark91()
    Dim i As Integer
    For i = 1 To 6
        Sheets("Line" & i).Columns("S:U").EntireColumn.Hidden = True
    Next i    
    Sheets("Line10").Columns("S:U").EntireColumn.Hidden = True
End Sub


Thank you Kpark91, it seems so simple now that I have the answer right in front of me.


JackDanIce: I haven't tested your code but I trust it works also, Thanks for the reply.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,833
Members
452,947
Latest member
Gerry_F

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