Conditionally Hide Rows

G

Guest

Hello everyone,

This is my second posting.

Does anyone know a VBA script to conditionally hide selected rows if they
equal zero or are left blank?

Please help.
 
G

Gord Dibben

Entire rows are 0 or blank?

Sub DeleteEmptyRows()
Dim LastRow As Long
''only if entire row is blank
LastRow = ActiveSheet.UsedRange.Row - 1 + _
ActiveSheet.UsedRange.Rows.Count
Application.ScreenUpdating = False
For r = LastRow To 1 Step -1
If Application.CountA(Rows(r)) = 0 Then Rows(r).Delete
Next r
End Sub

Just rows with a certain column's cells blank or zero?

Sub HideBlank_Zeros_Rows()
'using set column
Dim RngCol As Range
Dim i As Range
Set RngCol = Range("B1", Range("B" & Rows.Count). _
End(xlUp).Address)
For Each i In RngCol
If i.Value = "" Or i.Value = "0" Then _
i.EntireRow.Hidden = True
Next i
End Sub


Gord Dibben Excel MVP
 
G

Gord Dibben

Sorry about that tam!

Change the .delete line to entirerow.hidden = true

Sub DeleteEmptyRows()
Dim LastRow As Long
''only if entire row is blank
LastRow = ActiveSheet.UsedRange.Row - 1 + _
ActiveSheet.UsedRange.Rows.Count
Application.ScreenUpdating = False
For r = LastRow To 1 Step -1
If Application.CountA(Rows(r)) = 0 Then _
Rows(r).EntireRow.Hidden = True
Next r
End Sub


Gord
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top