ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Using VBA to Conditional Hide Rows? (https://www.excelbanter.com/excel-discussion-misc-queries/131057-using-vba-conditional-hide-rows.html)

PBJ

Using VBA to Conditional Hide Rows?
 
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.

Gary''s Student

Using VBA to Conditional Hide Rows?
 
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
--
Gary's Student
gsnu200706


"PBJ" wrote:

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.



All times are GMT +1. The time now is 10:38 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com