PDA

View Full Version : Hide Zero Values



BABAR RASHEE
03-13-2008, 04:10 AM
Dear All

i tried to use this code and help me to hide the rows with Zero values base on the Col Q. but there is one problem. i have some thing like 15 worksheet, and i make the 15 macros in all sheets. i just want to have a one code for all 15 sheet. means when i run the macros i should have one macros code and once i run it should work for all my sheets.

Thaks

Sub HideRowIfZeroInQ()
Dim R As Range
Dim LastRow As Long
LastRow = Cells(Rows.Count, "Q").End(xlUp).Row
If LastRow > 2800 Then LastRow = 2800
For Each R In Range("Q8:q" & CStr(LastRow))
If R.Value = 0 And R.Value <> "Q" Then R.EntireRow.Hidden = True
Next
End Sub

Simon Lloyd
03-13-2008, 04:28 AM
Try this:

Sub HideRowIfZeroInQ()
Dim R As Range
Dim LastRow As Long
For Each Sheet In Sheets
With Sheet
LastRow = .Cells(Rows.Count, "Q").End(xlUp).Row
If LastRow > 2800 Then LastRow = 2800
For Each R In Range("Q8:q" & CStr(LastRow))
If R.Value = 0 And R.Value <> "Q" Then R.EntireRow.Hidden = True
Next
End With
Next Sheet
End Sub

BABAR RASHEE
03-13-2008, 05:29 AM
No simon it does not work. only first sheet is active....

Simon Lloyd
03-13-2008, 05:45 AM
it worked fine for me!, are your other sheets hidden or protected?

Bob Phillips
03-13-2008, 05:51 AM
dot Range perhaps?

Simon Lloyd
03-13-2008, 05:51 AM
My fault sorry i missed a qualifier:

Sub HideRowIfZeroInQ()
Dim R As Range
Dim LastRow As Long
For Each Sheet In Sheets
With Sheet
LastRow = .Cells(Rows.Count, "Q").End(xlUp).Row
If LastRow > 2800 Then LastRow = 2800
For Each R In .Range("Q8:q" & CStr(LastRow))
If R.Value = 0 And R.Value <> "Q" Then R.EntireRow.Hidden = True
Next
End With
Next Sheet
End Sub

BABAR RASHEE
03-13-2008, 07:30 AM
Thanks alot. it works
Can i use the same code if i have column A,B,C ,D,E,F,G (i.e A,B,C,D "todate values") and E,F,G (is month todate), Now i just wana set up the macros to hide the rows based on these 3 (E,F,G) column. one thing in importnent that may be E have no value but F,G has a values or vise versa. so pls help to creat this code also.

Thanks

BABAR RASHEE
03-13-2008, 07:30 AM
Thanks alot. it works
Can i use the same code if i have column A,B,C ,D,E,F,G (i.e A,B,C,D "todate values") and E,F,G (is month todate), Now i just wana set up the macros to hide the rows based on these 3 (E,F,G) column. one thing in importnent that may be E have no value but F,G has a values or vise versa. so pls help to creat this code also.

Thanks