[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 71
  • Last Modified:

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.
BEFORE.JPGAFTER.JPG
I wish slicers could work this way across rows.
Book3.xlsx
0
chris pike
Asked:
chris pike
  • 2
  • 2
1 Solution
 
Rgonzo1971Commented:
Hi,

pls try in the Sheet module
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("B2")) Is Nothing Then
    If Target >= 1 And Target <= 8 Then
        Range("D1:K1").EntireColumn.Hidden = True
        Range("C1").Offset(, Target.Value).EntireColumn.Hidden = False
    End If
End If
End Sub

Open in new window

Regards
1
 
chris pikeAuthor Commented:
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
0
 
Rgonzo1971Commented:
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)
0
 
chris pikeAuthor Commented:
Awesome.
I have another fix I would like to be made.
Please see next question.
Thanks so much.
Chris
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now