Link to home
Start Free TrialLog in
Avatar of chris pike
chris pikeFlag for Canada

asked on

Excel to show only slected columns and hide the rest

Hi Experts,
I want to be able to choose ONE column and also have L and M columns shown. Column A,B,C will always be visable.

Example: User want to display Column "D", they would enter "D" into the field B2 and the sheet would hide Everything except "D" and "L" and "M".. Also keep in mind that "D" could be any column chosen.... E or F or G etc..

L and M of course will change later as the sheet grows.
User generated imageUser generated image
I wish slicers could work this way across rows.
Book3.xlsx
ASKER CERTIFIED SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of chris pike

ASKER

Awesome.
What is the C1 for and what is the <= 8  for?
The sheet will grow and it will have 60 or 70 columns of data, I need to change it easily.
Plus I love trying seeing how it works and trying to understand your coding, looks so simple.

Thanks so much
Chris
I have 2 other open questions.... wink wink
Avatar of Rgonzo1971
Rgonzo1971

this line is to restrict
    If Target >= 1 And Target <= 8 Then
the columns to be chosen

Range("C1").Offset(, Target.Value).EntireColumn
with offset displacing the position of the range ( definition Offset(Rows, Columns))
I could have written instead
Columns("D:D").Offset(, Target.Value - 1)
Awesome.
I have another fix I would like to be made.
Please see next question.
Thanks so much.
Chris