Need VBA code to hide multiple columns if row 2 in the same columns is a certain text value

jeff_cp

Board Regular
Joined
May 21, 2015
Messages
84
I have a spreadsheet that's pulling data from a database. In this database, the fields come from different globals in the software. One of these globals, ^YEV, is broken and all the fields in the database from this global return NULL values. I need to include these fields in the report but hide them until the database is fixed, which may be a while. I want to make sure any column with ^YEV in row 2 gets hidden each time I run my refreshAlll macro. Here's my layout:

ABCDE
1Account Information Report
2^YEV^YEV
3AccountNumAccountNameYearlySalesToDateAccountBalancePhoneNum
412345ABC Customer123-456-7890
523456XYZ Customer234-567-8901

So in the example above, I need to hide columns C and D because row 2 in each of those columns has ^YEV.

Thanks for any help with this!
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
VBA Code:
For c = 1 To Cells(2, Columns.Count).End(xlToLeft).Column
If Cells(2, c) = "^YEV" Then Columns(c).EntireColumn.Hidden = True
Next c
 
Upvote 0
Solution

Forum statistics

Threads
1,214,989
Messages
6,122,622
Members
449,093
Latest member
catterz66

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