Hid and unhide and clear contents for specific columns at the same time

  • Thread starter Thread starter hamad.fatima
  • Start date Start date
H

hamad.fatima

I have a serious problem with excel programming and i am not able to
figureout how to do the following funtions.

I have 24 columns. names Jan -Dec ( Actual) then Jan- Dec (Forecast).
There is one reference cell A1 ( for current month).
- If A1= Jan, I want macro to hide FEB-DEC 9 Actual , and leave
FEB-DEC (forecast).
-If A1= FEB , I want macro to unhide FEB Actual and hide MAR-Dec (
actual) and at the same time clear contents in FEB (forecast) and hide
feb (forecast ).

ANd so on


I would really appreciate if somene could help me figure out this
problem.

Thanks
 
Use one of these in the sheet module where cell a1 contains the number of
the month.

Sub hidecols()
Columns.Hidden = False
mc = Range("a1") + 1
Range(Cells(1, mc), Cells(1, 12)).EntireColumn.Hidden = True
End Sub

'Automatic every time you change cell a1
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address <> "$A$1" Then Exit Sub
Columns.Hidden = False
mc = Target + 1
Range(Cells(1, mc), Cells(1, 12)).EntireColumn.Hidden = True
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top