Macro to hide columns by Header Names

zalik22

Board Regular
Joined
Dec 14, 2010
Messages
122
Office Version
  1. 365
Platform
  1. Windows
Hi,

I am looking to hide columns by header names. The columns I would like to hide are "name", "date" and "age".

Thanks!
 
Columns(Col).Select

Run Time Error 91 Object Variable or With Block variable not set
 
Upvote 0

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Do you actually have a column called UserID in row 1?
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0
Glad to help & thanks for the feedback

Hi - I'm trying to run the following based on your initial suggestions but nothing seems to be happening?

Sub Hide_Me()
'"TR Trial Num", "TR Finance MU Cde", "TR Managing MU Cde", "TR Updating MU Cde", "TR Other Dsn Factors Multiple", "TR Objectives Multiple", "TR PA Fct", "TR FPV Fct", and "TR FPETrt Act"
Dim Lastcolumn As Long
Lastcolumn = Cells(1, Columns.Count).End(xlToLeft).Column
For i = 1 To Lastcolumn
If Cells(1, i).Value = "TR Trial Num" Or Cells(1, i).Value = "TR Finance MU Cde" Or Cells(1, i).Value = "TR Managing MU Cde" Or Cells(1, i).Value = "TR Updating MU Cde" Or Cells(1, i).Value = "TR Other Dsn Factors Multiple" Or Cells(1, i).Value = "TR Objectives Multiple" Or Cells(1, i).Value = "TR PA Fct" Or Cells(1, i).Value = "TR FPV Act" Or Cells(1, i).Value = "TR FPETrt Act" Then Columns(i).Hidden = True
Next
End Sub
 
Upvote 0
Do any of those values exist in row 1 of the active sheet?
 
Upvote 0
That's a different question, so you will need to start a new thread.
Thanks
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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