mistatasty
New Member
- Joined
- Jul 21, 2021
- Messages
- 23
- Office Version
- 365
- Platform
- Windows
I need to hide certain columns based on certain cells being 0 as well as hide certain rows when certain cells are 0. I had a previous code to auto hide/unhide the rows based on the reference cell changing from 0. It worked fine and when the 0 changed the row would automatically unhide. However, I tried to input the same sort of macro to hide columns, but now the columns wont unhide automatically when the reference cell changes from 0, it has to be done manually. What is wrong here?
Private Sub Worksheet_Calculate()
Dim c As Range
Application.EnableEvents = False
For Each c In Range("A26:A247")
If c.Value = "0" Then
Rows(c.Row & ":" & c.Row).EntireRow.Hidden = True
Else
Range(c.Row & ":" & c.Row).EntireRow.Hidden = False
End If
Next
Application.EnableEvents = True
End Sub
Sub Hide_Columns_Containing_Value()
Dim c As Range
Application.EnableEvents = False
For Each c In Range("e25:an25").Cells
If c.Value = "0" Then
c.EntireColumn.Hidden = True
Else
c.EntireColumn.Hidden = False
End If
Next
Application.EnableEvents = True
End Sub
Private Sub Worksheet_Calculate()
Dim c As Range
Application.EnableEvents = False
For Each c In Range("A26:A247")
If c.Value = "0" Then
Rows(c.Row & ":" & c.Row).EntireRow.Hidden = True
Else
Range(c.Row & ":" & c.Row).EntireRow.Hidden = False
End If
Next
Application.EnableEvents = True
End Sub
Sub Hide_Columns_Containing_Value()
Dim c As Range
Application.EnableEvents = False
For Each c In Range("e25:an25").Cells
If c.Value = "0" Then
c.EntireColumn.Hidden = True
Else
c.EntireColumn.Hidden = False
End If
Next
Application.EnableEvents = True
End Sub