Hide columns based on drop down list with various possibilities

Mr.Magic

New Member
Joined
May 4, 2011
Messages
9
Dear all,

I'm writing codes with as result that certain columns should be hidden when a specific choice is made in the drop down list.
Underneath the codes I use, which are very much simplified. In my real excel I have 7 in stead of 3 possibilities, and much much more columns to be hidden or to be shown.

Thanks a lot for helping me out!

CODE:

Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Address = "$B$2" Then

If LCase(Target.Text) = "All" Then

Columns("C").EntireColumn.Hidden = False
Columns("D").EntireColumn.Hidden = True
Columns("E").EntireColumn.Hidden = False

ElseIf LCase(Target.Text) = "Comptes bancaires" Then

Columns("C").EntireColumn.Hidden = True
Columns("D").EntireColumn.Hidden = False
Columns("E").EntireColumn.Hidden = False

ElseIf LCase(Target.Text) = "Terms deposit" Then

Columns("C").EntireColumn.Hidden = False
Columns("D").EntireColumn.Hidden = False
Columns("E").EntireColumn.Hidden = True

End if
End if
End sub
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Not quite sure what you are asking here :confused:
Adapt the code to match your 'Names' in the validation and give it a try;
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Select Case Range("B2").Value
Case Is = "Monday"
Columns("C:AA").EntireColumn.Hidden = False
Columns("D:M").EntireColumn.Hidden = True
Columns("G").EntireColumn.Hidden = False
Case Is = "Tuesday"
Columns("C:AA").EntireColumn.Hidden = False
Columns("C:Q").EntireColumn.Hidden = True
Columns("F").EntireColumn.Hidden = False
Case Is = "Wednesday"
Columns("C:AA").EntireColumn.Hidden = False
Columns("E:T").EntireColumn.Hidden = True
Columns("I").EntireColumn.Hidden = False
Case Is = "Thursday"
Columns("C:AA").EntireColumn.Hidden = False
Columns("D:M").EntireColumn.Hidden = True
Columns("K").EntireColumn.Hidden = False
End Select
End Sub

HTH
Colin
 
Upvote 0
i m sorry this is laymen, but is this code for a macro?

i am using a macro enabled workbook, which now i enabled the track changes feature.
this disables macro's (as per a popup msg when you click okay to enable.)
So the when its opened it says SHARED on it.

I need to hide columns based on pull down list from previous column.

Can i do that and still share and track changes ?

TY - Juliana
 
Upvote 0

Forum statistics

Threads
1,224,613
Messages
6,179,903
Members
452,948
Latest member
Dupuhini

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