Hide columns based on value in cell

kapilg89

New Member
Joined
Dec 12, 2012
Messages
30
Hi,

I want to hide unhide columns based on the criteria given in the cell
for eg: my cell a1 has programme life eg 5 years, so the columns for only five years should be visible and the rest of the columns, viz the rest 10 years, should be auto hidden.

Thanks in advance......
 
Just one more thing if i want to link the cell to a different sheet the would the code be any different?
Also i wanted a live updation of the macro. How to Achieve it?
 
Upvote 0

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Change Range("A1") to Range("H19") everywhere in the code.
 
Upvote 0
Then you should put code into "Basic info" sheet module and prefix with sheet those ranges which refer to C-Q range.
 
Upvote 0
I cannot find a way to link the sheet wherein the columns need hiding
Can you hel me
The sheet wherein the number of year is present is named "Basic Info" and the sheet wherein the columns need to be hidden is named as "Kit List and Volumes"
 
Upvote 0
In "Basic Info" sheet module:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)     If Target.Address = Range("A1").Address Then
        With Sheets("Kit List and Volumes")
            .Cells.EntireColumn.Hidden = False
            If Target.Value < 15 Then .Range(.Cells(1, Target.Value + 3), .Cells(1, 17)).EntireColumn.Hidden = True
        End With     End If End Sub</pre>
 
Upvote 0
It's because of incorrect forum's code formatting. Couldn't you fix it yourself?
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = Range("A1").Address Then
        With Sheets("Kit List and Volumes")
            .Cells.EntireColumn.Hidden = False
            If Target.Value < 15 Then .Range(.Cells(1, Target.Value + 3), .Cells(1, 17)).EntireColumn.Hidden = True
        End With
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,098
Messages
6,128,812
Members
449,468
Latest member
AGreen17

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