Hiding columns based on cell value

bence.andras

New Member
Joined
May 23, 2011
Messages
2
Hello there,

i'm making an automated report file, and what i would like to do is hide specific collumns that have no value or come 0.(in order to not show on a graph)

However the given month determines which collumns i do not want.
So i wrote this:


Private Sub Worksheet_Change(ByVal Target As Range)<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
If Target.Cells.Count = 1 And Target.Address = "$B$37" Then<o:p></o:p>
<o:p></o:p>
If LCase(Target.Value) = "jan'11" Then<o:p></o:p>
Columns("O:Y").EntireColumn.Hidden = True<o:p></o:p>
<o:p></o:p>
<o:p></o:p>
ElseIf LCase(Target.Value) = "feb'11" Then<o:p></o:p>
Columns("P:Y").EntireColumn.Hidden = True<o:p></o:p>
ElseIf LCase(Target.Value) = "1 q '11 qtd (jan&feb)" Then<o:p></o:p>
Columns("P:Y").EntireColumn.Hidden = True<o:p></o:p>
ElseIf LCase(Target.Value) = "1 q '11" Then<o:p></o:p>
Columns("Q:Y").EntireColumn.Hidden = True<o:p></o:p>
ElseIf LCase(Target.Value) = "apr '11" Then<o:p></o:p>
Columns("R:Y").EntireColumn.Hidden = True<o:p></o:p>
ElseIf LCase(Target.Value) = "may '11" Then<o:p></o:p>
Columns("S:Y").EntireColumn.Hidden = True<o:p></o:p>
ElseIf LCase(Target.Value) = "2 q '11 qtd (apr&may)" Then<o:p></o:p>
Columns("S:Y").EntireColumn.Hidden = True<o:p></o:p>
ElseIf LCase(Target.Value) = "2 q '11" Then<o:p></o:p>
Columns("T:Y").EntireColumn.Hidden = True<o:p></o:p>
ElseIf LCase(Target.Value) = "jul '11" Then<o:p></o:p>
Columns("U:Y").EntireColumn.Hidden = True<o:p></o:p>
ElseIf LCase(Target.Value) = "aug '11" Then<o:p></o:p>
Columns("V:Y").EntireColumn.Hidden = True<o:p></o:p>
ElseIf LCase(Target.Value) = "3 q '11 qtd (jul&aug)" Then<o:p></o:p>
Columns("V:Y").EntireColumn.Hidden = True<o:p></o:p>
ElseIf LCase(Target.Value) = "3 q '11" Then<o:p></o:p>
Columns("W:Y").EntireColumn.Hidden = True<o:p></o:p>
ElseIf LCase(Target.Value) = "oct '11" Then<o:p></o:p>
Columns("X:Y").EntireColumn.Hidden = True<o:p></o:p>
ElseIf LCase(Target.Value) = "nov '11" Then<o:p></o:p>
Columns("Y:Z").EntireColumn.Hidden = True<o:p></o:p>
ElseIf LCase(Target.Value) = "4 q '11 qtd (oct&nov)" Then<o:p></o:p>
Columns("Y:Z").EntireColumn.Hidden = True<o:p></o:p>
ElseIf LCase(Target.Value) = "4 q '11" Then<o:p></o:p>
Columns("O:Y").EntireColumn.Hidden = False<o:p></o:p>
ElseIf LCase(Target.Value) = "fy11" Then<o:p></o:p>
Columns("O:Y").EntireColumn.Hidden = False<o:p></o:p>
<o:p></o:p>
<o:p></o:p>
Else<o:p></o:p>
Columns("A:Z").EntireColumn.Hidden = False<o:p></o:p>
End If<o:p></o:p>
<o:p></o:p>
End If<o:p></o:p>
<o:p></o:p>
End Sub<o:p></o:p>


However my problem is that the cell which gives me the month is a vlookup function and not simply the text. So it doesn't work. If i type in the same thing there manually, then it does the job. (although another problem is when i pick a next month it doesnt change the hidden collumns, but **** that...)

Can somebody help me how to solve this issue. (please note that im at a very very beginner level with excel, so sorry for any obvious questions)
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Nobody on this one?

I would take any advice on hiding my collumns unnecessary (containing just 0s) so that the chart that is created automatically when new file links are put don't look that screwed...
 
Upvote 0

Forum statistics

Threads
1,223,891
Messages
6,175,229
Members
452,621
Latest member
Laura_PinksBTHFT

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