ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Hide colums based on dropdown list (https://www.excelbanter.com/excel-programming/312588-hide-colums-based-dropdown-list.html)

mgronov - ExcelForums.com

Hide colums based on dropdown list
 
I like to be able to hide/unhide colums based on a dropdown lis
selection
The 1st column starts in K and the 7th column in Q

If dropdown selection = 1, then hide columns L to Q, show columns
If dropdown selection = 2, then hide columns M to Q, show columns K-
Etc til
If dropdown selection = 2, then show columns K to

Is there a way to do this in VBA. I've been trying to do this bu
without any success
Any help is appreciated

Michae
--------
Message sent via www.excelforums.com

David Adamson[_4_]

Hide colums based on dropdown list
 
Michael,

Adapt the following
------
Private Sub Selection_Change()
'selection.value , 'selection = the dropdown boxes name

Select Case Selection.Value

Case 1
Worksheets("Data").Range("a1:c1").EntireColumn.Hid den = True
Worksheets("Data").Range("d1:e1").EntireColumn.Hid den = False

Case 2
Worksheets("Data").Range("a1:c1").EntireColumn.Hid den = False
Worksheets("Data").Range("d1:e1").EntireColumn.Hid den = True

Case 3

End Select
End Sub

----
David



mgronov - ExcelForums.com

Hide colums based on dropdown list
 
David
I've modified your code. But I get the [quote:66f5bed38c
Object Required[/quote:66f5bed38c] error message. and it already stop
at Select Cas
DropDown125.Valu
The name of the dropdown is DropDown12
This is the first time I'm trying VBA so sorry for an
stupid questions :oops:

[code:1:66f5bed38c]Sub DropDown125_Change(
Select Case DropDown125.Valu

Case
Worksheets("Data").Range("l1:q1").EntireColumn.Hid de
= Tru
Worksheets("Data").Range("k1:k1").EntireColumn.Hid de
= Fals

Case
Worksheets("Data").Range("k1:l1").EntireColumn.Hid de
= Fals
Worksheets("Data").Range("m1:q1").EntireColumn.Hid de
= Tru

Case
Worksheets("Data").Range("k1:m1").EntireColumn.Hid de
= Fals
Worksheets("Data").Range("n1:q1").EntireColumn.Hid de
= Tru

Case
Worksheets("Data").Range("k1:n1").EntireColumn.Hid de
= Fals
Worksheets("Data").Range("o1:q1").EntireColumn.Hid de
= Tru

Case
Worksheets("Data").Range("k1:o1").EntireColumn.Hid de
= Fals
Worksheets("Data").Range("p1:q1").EntireColumn.Hid de
= Tru

Case
Worksheets("Data").Range("k1:p1").EntireColumn.Hid de
= Fals
Worksheets("Data").Range("r1:q1").EntireColumn.Hid de
= Tru

Case
Worksheets("Data").Range("k1:q1").EntireColumn.Hid de
= Fals

End Selec
End Su
[/code:1:66f5bed38c][/i
--------
Message sent via www.excelforums.com

David Adamson[_4_]

Hide colums based on dropdown list
 
Okay the problem is probably this.

I ran my code from a userform and you are probably using a dropdown box on a
worksheet

This is what you need to change to set the object

-------------------
Sub DropDown125_Change()
Dim r As Double

With Worksheets("Data")

r = .DropDowns("drop down 125").Value
End With

Select Case r
Case 1
'code as you have

End
---------------

Hope this solves the problem


"mgronov - ExcelForums.com"
wrote in message ...
David,
I've modified your code. But I get the [quote:66f5bed38c]
Object Required[/quote:66f5bed38c] error message. and it already stops




mgronov - ExcelForums.com

Hide colums based on dropdown list
 
David
You rock! It works great :D
Thanks

Michae
--------
Message sent via www.excelforums.com


All times are GMT +1. The time now is 03:04 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com