code for how to show only certain columns based on the current visible columns

kbishop94

Active Member
Joined
Dec 5, 2016
Messages
457
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Confusing question, I know. Not sure how to explain it better though (I’m not very good sometimes at trying to effectively communicate what I am wanting… sorry)

So I have a spreadsheet (shown below) that when choosing a certain button (the buttons represent specific departments) the code will highlight only the procedures (rows) specific to that department along with an ‘X’ if that person has been trained for that procedure, and also reducing down the names to only the people that work in that department... (it works pretty slick, if I do say so myself... lol)

Speadsheet as it appears when it is first opened:



Screenshot of the spreadsheet with just the names showing for the "Labels" department (after the labels button is selected)


Ok... now there are hidden column(s) that are to the right of the visible column that shows an "X" (or the cell where an "X" would be) and these are the ones that I need to be visible upon executing the code (ill put in another button for this.)

So when hitting this new button it will look like this:



So what I need is code that when exectuted it will show only columns that are to the right of the visible column(s) that have a name in them. In this case those would be column CH, DX, DZ, and so on...


Is something like this possible? Thank you!
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
If I understand what you need then try this.


This will undte the Column to the right of and cell that has and X in it that is not Hidden.
adjust Range as needed

Code:
For Each cell In Range("D6:ZZ500")
If cell.Value = "X" And Columns(cell.Column).Hidden = False Then Columns(cell.Column + 1).Hidden = False
Next cell

hth,

Ross
 
Last edited:
Upvote 0

Forum statistics

Threads
1,213,544
Messages
6,114,249
Members
448,556
Latest member
peterhess2002

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