Solved

Excel to show only slected columns and hide the rest

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

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,…
Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

809 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