Macro if cell equals 0

Solved
peybernes Posted messages 50 Registration date   Status Member Last intervention   -  
peybernes Posted messages 50 Registration date   Status Member Last intervention   -
Hello everyone,

I'm currently working on an Excel file and I need your help!
I would like to create a macro that hides a row if a specific cell in that row equals 0.
The row should only be hidden if there is a 0 in the cell.
I had a solution, but it also hides the row when the cell is empty...
Here it is:
If Range ("AB2") = 0 Then
Rows("2:2").Select
Selection.EntireRow.Hidden = True
End If

Thank you for your help

Best regards

Peybernes

1 answer

gbinforme Posted messages 14930 Registration date   Status Contributor Last intervention   4 743
 
Hello,

You can do it this way while avoiding 'select':
If Range("AB2").Value = 0 And Range("AB2").Value <> "" Then Rows(2).EntireRow.Hidden = True 

Always zen
Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away. Antoine de Saint-Exupéry
1
peybernes Posted messages 50 Registration date   Status Member Last intervention  
 
Perfect!

Thank you very much.
0