Problem with this code
Hi,
I have found this code, posted by "NO SPAM". Somehow I get an error at "If" after "step-1". Whats wrong? I think this code would help me to get what I need, but I cant get i work like this. Thanks in advance //Thomas Sub CleanUp() Dim CurrentRow As Long Dim UsedRows As Range On Error GoTo Abort Set UsedRows = ActiveSheet.UsedRange.Rows For CurrentRow = UsedRows.Rows.Count To 1 Step -1 If Application.WorksheetFunction.Sum(UsedRows.Rows(Cu rrentRow).Columns("B:B")) = 0 Then UsedRows.Rows(CurrentRow).EntireRow.Hidden = True Else UsedRows.Rows(CurrentRow).EntireRow.Hidden = False End If Next CurrentRow ' If only hiding for printing purposes, use the next two lines to prin or preview then restore the worksheet 'ActiveWindow.SelectedSheets.PrintPreview 'ActiveSheet.Rows.EntireRow.Hidden = False Abort: End Su -- Message posted from http://www.ExcelForum.com |
Problem with this code
The 3 lines
If Application.WorksheetFunction.Sum(UsedRows.Rows(Cu rrentRow).Columns("B:B")) = 0 Then should all be one line, but seem to have wrapped around in the NG -- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) "Jonsson " wrote in message ... Hi, I have found this code, posted by "NO SPAM". Somehow I get an error at "If" after "step-1". Whats wrong? I think this code would help me to get what I need, but I cant get it work like this. Thanks in advance //Thomas Sub CleanUp() Dim CurrentRow As Long Dim UsedRows As Range On Error GoTo Abort Set UsedRows = ActiveSheet.UsedRange.Rows For CurrentRow = UsedRows.Rows.Count To 1 Step -1 If Application.WorksheetFunction.Sum(UsedRows.Rows(Cu rrentRow).Columns("B:B")) = 0 Then UsedRows.Rows(CurrentRow).EntireRow.Hidden = True Else UsedRows.Rows(CurrentRow).EntireRow.Hidden = False End If Next CurrentRow ' If only hiding for printing purposes, use the next two lines to print or preview then restore the worksheet 'ActiveWindow.SelectedSheets.PrintPreview 'ActiveSheet.Rows.EntireRow.Hidden = False Abort: End Sub --- Message posted from http://www.ExcelForum.com/ |
Problem with this code
|
All times are GMT +1. The time now is 10:50 AM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com