Hide rows with zero's on several sheets within a workbook
My apologies, there was a bug in it. Corrected code
Sub HideRowsIfColumnDisEmpty()
Dim sh As Long
Dim X As Long
Dim LastRowOfData As Long
For sh = 1 To Sheets.Count
Sheets(sh).Select
If ActiveSheet.Name < ("FunctionalSummaryTotalRisk") And
ActiveSheet.Name < _
("FunctionalSummaryTotalFinanc") Then
LastRowOfData = Cells(Rows.Count, "N").End(xlUp).Row
For X = 1 To LastRowOfData
If Cells(X, "N").Value = 0 Then
Cells(X, "N").EntireRow.Hidden = True
End If
Next
End If
Next
End Sub
"khurram_razaq" wrote:
Hi Mike,
I tired this but the code is not doing anything at all.
Any suggestions?
Khurram
"Mike H" wrote:
Try this
Sub HideRowsIfColumnDisEmpty()
Dim sh As Long
Dim X As Long
Dim LastRowOfData As Long
For sh = 1 To Sheets.Count
If ActiveSheet.Name < ("FunctionalSummaryTotalRisk") And
ActiveSheet.Name < _
("FunctionalSummaryTotalFinanc") Then
LastRowOfData = Cells(Rows.Count, "N").End(xlUp).Row
For X = 1 To LastRowOfData
MsgBox ActiveSheet.Name
If Cells(X, "N").Value = 0 Then
Cells(X, "N").EntireRow.Hidden = True
End If
Next
End If
Next
End Sub
Mike
"khurram_razaq" wrote:
Hi,
I tried to use the below code with some changes but get a error message,
"Subscript out of range".
Sub HideRowsIfColumnDisEmpty()
Dim sh As Long
Dim X As Long
Dim SheetNumbers As Variant
Dim LastRowOfData As Long
SheetNumbers = Array(FunctionalSummaryTotalRisk, FunctionalSummaryTotalFinanc)
For sh = SheetNumbers(1) To SheetNumbers(2)
Sheets(sh).Activate
LastRowOfData = Cells(Rows.Count, "N").End(xlUp).Row
For X = 1 To LastRowOfData
If Cells(X, "N").Value = 0 Then
Cells(X, "N").EntireRow.Hidden = True
End If
Next
Next
End Sub
Basically there are a total of 12 worksheets in the workbook and I only want
ot apply this to 2 which are FunctionalSummaryTotalRisk,
FunctionalSummaryTotalFinanc.
Please help.
Thanks.
Khurram
" wrote:
Hi
Try this. not tested.
Sub HideRowsIfColumnDisEmpty()
Dim sh As Long
Dim X As Long
Dim SheetNumbers as Variant
Dim LastRowOfData As Long
SheetNumbers = Array(1,3,4)
For sh = SheetNumbers(1) To SheetNumbers(3)
Sheets(sh).Activate
LastRowOfData = Cells(Rows.Count, "N").End(xlUp).Row
For X = 1 To LastRowOfData
If Cells(X, "N").Value = 0 Then
Cells(X, "N").EntireRow.Hidden = True
End If
Next
Next
End Sub
regards
Paul
On Jun 6, 9:52 am, khurram_razaq
wrote:
Hi,
I recently got some help on getting a VBA code to hide rows with zero.
However what I want to do is modilfy it so that I can run it only on specific
sheets within a workbook. For example if there are 4 work sheet, sheet1,
sheet2, sheet3 and
sheet4 and I want one marco but want to apply it to sheet 1, sheet3 and sheet
4 only what changes will I need to make to the code below?
Sub HideRowsIfColumnDisEmpty()
Dim sh As Long
Dim X As Long
Dim LastRowOfData As Long
For sh = 1 To Sheets.Count
Sheets(sh).Activate
LastRowOfData = Cells(Rows.Count, "N").End(xlUp).Row
For X = 1 To LastRowOfData
If Cells(X, "N").Value = 0 Then
Cells(X, "N").EntireRow.Hidden = True
End If
Next
Next
End Sub
Thank you for your help.
Khurram
|