Add/Hide Columns based on value

Cworm

New Member
Joined
Aug 24, 2011
Messages
11
I need an auto macro to hide columns based on a date. The date will be manually typed in at cell "End_Date7.0" .

The row that will have a date in it is row 12. I need to hide the columns that contain a date past the date entered for "End_Date7.0". The range for the columns are D-BF (the specific data is coded as "Whole_Res_7.0"). I would like this macro to update whenever someone has entered data into the "End_Date7.0" cell. So if they entered a different date, the hidden columns would re-appear.

Any help would be greatly appreciated!
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
So the cells that would indicate which columns are hidden are B12-DF12?

What cell contains the date for "End_Date7.0"?
 
Upvote 0
And yes, the cells that would indicate the columns hidden are B12-DF12. If in B12 the date is greater than the date in D8, I would like B column to be hidden. If it is not greater than that date, I would like the column to unhide. Make sense?
 
Upvote 0
D8 of the same sheet where the columns are to be hidden?

If no, what is the sheet name with D8?

What is the sheet name with the columns to be hidden/unhidden?
 
Upvote 0
Yes, it is all on the same sheet... "7.0 Resource Allocation" this is the only sheet this calculation is needed for.

Thank you for your time
 
Upvote 0
Oh sorry...it starts at F - DF for row 12 data. I am sorry. Nothing will be hidden before column F
 
Upvote 0
Right click on the tab, select View code and paste this in (save as a copy of your workbook)
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range
If Intersect(Range("D8"), Target) Is Nothing Then Exit Sub
Range("F:DF").EntireColumn.Hidden = False
For Each c In Range("F12:DF12")
If c.Value > Range("D8").Value Then c.EntireColumn.Hidden = True
Next c
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,565
Messages
6,179,549
Members
452,927
Latest member
rows and columns

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