Hide / Unhide Rows

Manrique

New Member
Joined
Aug 20, 2014
Messages
24
Hello,

Need VBA to hide rows when values on column E are zero and unhide them if they change to <> 0.

Thanks for your help!
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
If the cells are hidden, how do you propose to put something other than zero into them to unhide them? You may want to rethink this.
 
Upvote 0
If the cells are hidden, how do you propose to put something other than zero into them to unhide them? You may want to rethink this.

Thank you alansidman:
Cells are not empty, they have a formula and their value changes as per information is added or subtracted from other cells.
 
Upvote 0
Thank you alansidman:
Cells are not empty, they have a formula and their value changes as per information is added or subtracted from other cells.

Try this:
Code:
Private Sub Worksheet_Calculate()


Dim Cell As Range
On Error GoTo ErrHandler

'put your own cells here
For Each Cell In Range("C37:C38,C40:C45,A54:A58")
Application.ScreenUpdating = False
Application.EnableEvents = False
ThisWorkbook.Sheets("Name of Your Worksheet").Unprotect
    If Cell.Value > 0 Then
    Cell.EntireRow.Hidden = False
Else
    Cell.EntireRow.Hidden = True
End If
Next


ErrHandler:
Application.ScreenUpdating = True
Application.EnableEvents = True
ThisWorkbook.Sheets("Name of Your Worksheet").Protect


End Sub
 
Upvote 0
Works great! Thanks for your help

Try this:
Code:
Private Sub Worksheet_Calculate()


Dim Cell As Range
On Error GoTo ErrHandler

'put your own cells here
For Each Cell In Range("C37:C38,C40:C45,A54:A58")
Application.ScreenUpdating = False
Application.EnableEvents = False
ThisWorkbook.Sheets("Name of Your Worksheet").Unprotect
    If Cell.Value > 0 Then
    Cell.EntireRow.Hidden = False
Else
    Cell.EntireRow.Hidden = True
End If
Next


ErrHandler:
Application.ScreenUpdating = True
Application.EnableEvents = True
ThisWorkbook.Sheets("Name of Your Worksheet").Protect


End Sub
 
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,323
Members
449,077
Latest member
jmsotelo

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