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

slk1987

New Member
Joined
Dec 29, 2022
Messages
8
Office Version
  1. 2021
Platform
  1. Windows
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
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
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:

VBA Code:
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
 
Upvote 0
Solution
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:

VBA Code:
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
That worked great, realy appreciate your help/quick reply!
 
Upvote 0

Forum statistics

Threads
1,224,813
Messages
6,181,107
Members
453,021
Latest member
Justyna P

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