Solved

Excel to show only slected columns and hide the rest

Posted on 2016-09-28
4
43 Views
Last Modified: 2016-09-29
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
Comment
Question by:chris pike
  • 2
  • 2
4 Comments
 
LVL 49

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 41820585
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
 

Author Comment

by:chris pike
ID: 41820596
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
 
LVL 49

Expert Comment

by:Rgonzo1971
ID: 41821161
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
 

Author Closing Comment

by:chris pike
ID: 41821632
Awesome.
I have another fix I would like to be made.
Please see next question.
Thanks so much.
Chris
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now