Hiding/Showing Columns Based on Drop-Down List - VBA

rubenidas

New Member
Joined
Aug 10, 2016
Messages
11
Hi All,
I have been struggling to get this working. I am trying to hide columns (C thru AA is the range) based on the value selected from the drop down in cell A12. The values are something like "Show All Details", "Show Financials", "Show KPI Results".... etc. For Example, i want to hide Columns B:O (B thru O) if "SHow KPI Results" is selected.

Your help is greatly appreciated!!

Code:
 Private Sub Worksheet_Change(ByVal Target As Range)Dim rTargetcell As Excel.Range


    Set rTargetcell = Range("A12")
If rTargetcell Is blank Then
Columns("B:AA").EntireColumn.Hidden = False
Else


Select Case Range("A12").Value


    Case "Show KPI Results"
      Columns("B:O").EntireColumn.Hidden = True


    Case "Show Financials"
      Columns("P").EntireColumn.Hidden = True
      Columns("R").EntireColumn.Hidden = True
    
End Select
End If
End Sub
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
This seems to work.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A12")) Is Nothing Then
    ActiveSheet.Columns.Hidden = False
    Select Case Target.Value
        Case "Show KPI Results"
          Columns("B:O").EntireColumn.Hidden = True
    
    
        Case "Show Financials"
          Columns("P").EntireColumn.Hidden = True
          Columns("R").EntireColumn.Hidden = True
    End Select
End If
End Sub
 
Upvote 0
Thanks! it worked.. i figured out i have to put the code into the sheet itself...not under Module.. Darn it! all this time i couldn't figure out why it was not working for me.. haha

This seems to work.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A12")) Is Nothing Then
    ActiveSheet.Columns.Hidden = False
    Select Case Target.Value
        Case "Show KPI Results"
          Columns("B:O").EntireColumn.Hidden = True
    
    
        Case "Show Financials"
          Columns("P").EntireColumn.Hidden = True
          Columns("R").EntireColumn.Hidden = True
    End Select
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,246
Members
452,623
Latest member
cliftonhandyman

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