I have some code creating up to 55 or 60 sheets. The final sheets are basically income statements that have accounts on each row and columns for months.
Everything worked fine until the users found some information was missing.
In order to eliminate zero rows (accounts without any dollars), I used the following code
I think I got some help here or on another forum to get the right syntax and it works based on the philosophy that if the total sum of the row is zero, delete it. This was based on an assumption that I would not have data that looked like
So as you can see the sum the row is zero but there is real data there so I cannot delete it (currently it is being deleted).
I've been trying to find a way around this. My first thought was to cycle through each column on each row and look for a non-zero number. If I find it, jump out of the loop and move to the next row. If not, then add it to the range to delete.
I figured there had to be a better way of doing it without a loop but I've been searching the sites for the last hour and can only find looping ideas like I originally had. I'm not against doing it but with so many sheets and upwards of 400 rows, it could take some time even with screen updating, calculations and alerts turned off.
Does anyone have a better idea? TIA, rasinc
Everything worked fine until the users found some information was missing.
In order to eliminate zero rows (accounts without any dollars), I used the following code
Code:
For x = lngLastRow To 6 Step -1
If Application.WorksheetFunction.Sum(Range("D" & x & ":AH" & x)) = 0 Then
If rngRangeToDelete Is Nothing Then
Set rngRangeToDelete = Cells(x, 2)
Else
Set rngRangeToDelete = Union(rngRangeToDelete, Cells(x, 2))
End If
End If
Next x
If rngRangeToDelete Is Nothing Then
Else
rngRangeToDelete.EntireRow.Delete
End If
I think I got some help here or on another forum to get the right syntax and it works based on the philosophy that if the total sum of the row is zero, delete it. This was based on an assumption that I would not have data that looked like
Code:
0 0 240 0 0 0 -240 0 0 0
So as you can see the sum the row is zero but there is real data there so I cannot delete it (currently it is being deleted).
I've been trying to find a way around this. My first thought was to cycle through each column on each row and look for a non-zero number. If I find it, jump out of the loop and move to the next row. If not, then add it to the range to delete.
I figured there had to be a better way of doing it without a loop but I've been searching the sites for the last hour and can only find looping ideas like I originally had. I'm not against doing it but with so many sheets and upwards of 400 rows, it could take some time even with screen updating, calculations and alerts turned off.
Does anyone have a better idea? TIA, rasinc