Howdy,
I'm running a module to format some data and have run into an issue with my logic. The piece that's giving me trouble is looping though a sheet, row by row and checking for a 0 balance. If it finds a 0 (in cell "G" & row), then it deletes the entire row. The problem is I have adjacent rows with 0 balances, so when my loop deletes one row, the other one shifts up, but my counter (row) moves forward one. So it misses the adjacent 0. I'm sure you fine folks probably have a fix for this. Help. thanks (as always).
I'm running a module to format some data and have run into an issue with my logic. The piece that's giving me trouble is looping though a sheet, row by row and checking for a 0 balance. If it finds a 0 (in cell "G" & row), then it deletes the entire row. The problem is I have adjacent rows with 0 balances, so when my loop deletes one row, the other one shifts up, but my counter (row) moves forward one. So it misses the adjacent 0. I'm sure you fine folks probably have a fix for this. Help. thanks (as always).
Code:
'delete zero qty rows
mylastrow = Cells.Find("*", [A1], , , xlByRows, xlPrevious).Row
For R = 2 To mylastrow
Range("G" & R).Select
If Range("G" & R) = "0" Then Rows(R).EntireRow.Delete
Next R