Hide columns based on cell value

  • Thread starter Thread starter bill.shut
  • Start date Start date
B

bill.shut

I have a IF formula in a cells H4:M4 that says HIDE or UNHIDE based on
a condition in another cell. I want to hide the column based on the
HIDE/UNHIDE value of the formula. I want to be able to change which
columns are hidden based on the result of the IF formula, as it changes
depending on the condition in another cell. I tried to follow some of
the macros in the forum, but got lost as most refer to hiding rows.

Thanks, Bill
 
One way:

Put this in your worksheet code module (right-click the worksheet tab
and choose View Code):

Private Sub Worksheet_Calculate()
Dim rCell As Range
For Each rCell In Range("H4:M4")
rCell.EntireColumn.Hidden = (rCell.Value = "HIDE")
Next rCell
End Sub
 
Back
Top