Help with Hiding Columns Macro

Mobot99

New Member
Joined
Jul 31, 2020
Messages
13
Office Version
  1. 365
Platform
  1. Windows
Hello, need help with a macro that hides columns in multiple worksheets based on whether the drop down menu in that column in one worksheet says "HIDE"

Here is what I have so far, my issue is how do I exclude certain worksheets? Including the worksheet that the macro is in? Or I can just include certain worksheets, whichever is easier.

Sub Hide_Columns_Containing_Value_All_Sheets()

Dim c As Range
Dim ws As Worksheet

For Each ws In ActiveWorkbook.Worksheets
If Not ws.Name = "Sheet9" Then
End If
For Each c In Range("D4:N4").Cells
If c.Value = "HIDE" Then
c.EntireColumn.Hidden = True
End If
Next c
Next ws
End Sub
 
Which line gives that error?
 
Upvote 0

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Not showing a particular line, here is a screenshot:
 

Attachments

  • Capture.PNG
    Capture.PNG
    56.8 KB · Views: 6
Upvote 0
Ok, Sheet9 is the code name, not the sheet name. The sheet name is Renewal Column Selection.
Try this instead
VBA Code:
Sub Hide_Columns_Containing_Value_All_Sheets()
   
   Dim c As Range
   Dim ws As Worksheet
   
   For Each ws In ActiveWorkbook.Worksheets
      Select Case ws.CodeName
         Case "Sheet9", "Sheet8", "Sheet3", "Sheet6" ' sheet names to be excluded
         Case Else
            For Each c In Sheet9.Range("D4:N4").Cells
               ws.Range(c.Address).EntireColumn.Hidden = c.Value = "HIDE"
            Next c
      End Select
   Next ws
End Sub
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,864
Members
449,052
Latest member
Fuddy_Duddy

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