VBA to hide colums based on dropdown list value

Edmund

New Member
Joined
Jan 12, 2016
Messages
8
Hi there,

I need vba automatically hide colums based on dropdown list value. Thanks in advance.
 

Attachments

  • Hide_columns_dropdown list.jpg
    Hide_columns_dropdown list.jpg
    217.1 KB · Views: 9

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
@Edmund. Maybe try this.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
Set MyRange = Range("E3:P3")

If Intersect(Target, Range("C3")) Is Nothing Then Exit Sub

Application.ScreenUpdating = False
MyRange.EntireColumn.Hidden = False
For Each Cell In MyRange
    If Not Cell = Target Then
        Cell.EntireColumn.Hidden = True
        c = c + 1
    End If
Next Cell
'unhide if c3 not a truck
If c = MyRange.Columns.Count Then MyRange.Columns.EntireColumn.Hidden = False

Application.ScreenUpdating = True

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,732
Members
448,987
Latest member
marion_davis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top