Macro code to hide columns

Chi_IC_Hawk

New Member
Joined
Jun 7, 2011
Messages
2
Hi all -

I have an accounting 13 week cash flow statement where I need to hide columns. The cash flow statement has 52 columns (one for each week) starting in column E and running through BD. In row 3, I have a formula that returns a value if the week is in the current 13 week cash flow. If it isn't, it returns "" (or null).

This is the code I currently have:

Sub HideColumns()
Dim e As Integer
For e = 5 To 56
If Len(ActiveSheet.Cells(3, e).Value) = 0 Then
ActiveSheet.Columns(e).Hidden = True
End If
Next
End Sub

Unfortunately, the way I have this entered, this only does one of the tabs. The file covers multiple worksheets and I need to apply them to a subset of the worksheets.

I know absolutely nothing about macros (I found the above one online after searching). If anybody can provide guidance, please help.

Thanks so much in advance!
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Try like this

Code:
Sub HideColumns()
Dim e As Integer, ws As Worksheet
For Each ws In Worksheets(Array("Sheet1", "Sheet7", "Data"))
    For e = 5 To 56
        If Len(ws.Cells(3, e).Value) = 0 Then
            ws.Columns(e).Hidden = True
        End If
    Next e
Next ws
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,733
Members
452,939
Latest member
WCrawford

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