Solved

Excel to show only slected columns and hide the rest

Posted on 2016-09-28
4
36 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 48

Accepted Solution

by:
Rgonzo1971 earned 500 total points
Comment Utility
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
Comment Utility
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 48

Expert Comment

by:Rgonzo1971
Comment Utility
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
Comment Utility
Awesome.
I have another fix I would like to be made.
Please see next question.
Thanks so much.
Chris
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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,…
Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

772 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

15 Experts available now in Live!

Get 1:1 Help Now