Using VBA to Conditional Hide Rows?

G

Guest

I have a sheet with a very long list of items in Column A, which may ormay
not have figures in the columns to the right. Since the list is so long, I'd
really like to only see those rows in which an item iin the first column does
have non-zero figures to the right. I can do this manually, I know, but this
sheet updates and is printed daily, and it would save a LOT of time and paper
if I could program it so that the rows would hide whenever there are all
zeroes to the right.

I'd think I should be able to do something in VBA so tha rows conditionally
hide when--to use row 2 as an example-- cells B2:Z2 = 0. Is this possible?

Thanks for any help anyone can offer.
 
G

Guest

If B2 thru Z2 are all zero, then the sum(B2:Z2) will be zero:

Sub pbj()
Dim r As Range
Set r = ActiveSheet.UsedRange
n = nLastRow + r.Rows.Count + r.Row - 1
For i = 1 To n
s = "B" & i & ":" & "Z" & i
Set r = Range(s)
If Application.WorksheetFunction.Sum(r) = 0 Then
r.EntireRow.Hidden = True
End If
Next
End Sub
 

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