# Hide Corresponding Rows based if first cell (a7-a72) = 0



## slk1987 (Dec 29, 2022)

Hello,

I am very new to VBA and looking for help hiding rows if the the first cell (Column A) in the row (7-72) is zero. I would also like to unhide the rows if the cell is not zero and ideally not have to manually run the code each time the values in column A change. Column A is dependent on changes to two cells on another sheet 'Client Profile'!C4:C5.

 This is not working as of now but I have pieced together the following:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "'Client Profile'!C4:C5" Then

Application.ScreenUpdating = False
Application.Calculation = xlManual

For Each c In Range("A7:A72")
    If c.Value = 0 Then Rows(c.Row).Hidden = True
Next

For Each c In Range("A7:A72")
    If c.Value > 1 Then Rows(c.Row).Hidden = False

Application.Calculation = xlAutomatic
Application.ScreenUpdating = True

End If
End Sub


----------



## bebo021999 (Dec 29, 2022)

Is the code placed in sheet "Client Profile" module? It should be.
Right click on Sheet "Client Profile" tab, then view code, then paste below code into:


```
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim i&
If Intersect(Target, Range("C4:C5")) Is Nothing Then Exit Sub ' if C4 or C5 does not change then do nothing
With Sheets("Sheet1") ' reference to A2:A72 of sheet1
    .Rows("7:72").Hidden = False ' first, unhide all rows
    For i = 7 To 72
        If .Cells(i, 1).Value = 0 Then .Rows(i).Hidden = True ' hide rows those = 0
    Next
End With
End Sub
```


----------



## breynolds0431 (Dec 29, 2022)

Removed duplicate solution.


----------



## slk1987 (Dec 30, 2022)

bebo021999 said:


> Is the code placed in sheet "Client Profile" module? It should be.
> Right click on Sheet "Client Profile" tab, then view code, then paste below code into:
> 
> 
> ...


That worked great, realy appreciate your help/quick reply!


----------

