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

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

alansidman

Well-known Member
Joined
Feb 26, 2007
Messages
7,493
Office Version
  1. 365
Platform
  1. Windows
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

Manrique

New Member
Joined
Aug 20, 2014
Messages
24
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

LBinGA

Board Regular
Joined
Jan 29, 2014
Messages
57
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

Manrique

New Member
Joined
Aug 20, 2014
Messages
24
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,191,592
Messages
5,987,524
Members
440,099
Latest member
wai2kit

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
Top