Hi All,
I am trying to write code to cycle through rows in an excel spreadsheet and delete the row if the end column is less than 1.
The code does delete the rows correctly however as it is a For x = y to z means that when a row is deleted the z does not reduce.
I tried to fixed this by reducing the z (in this case it is FinalRowFcstSheet) by -1 if a row has been deleted, however the RowNo goes beyond the FinalRowFcstSheet number and seems to continue on till the initial FinalRowFcstSheet value of circa 45,000, I have to stop the code as runs for a very long time.
below is the code is there an easy fix or a different way to achieve what I am trying to do.
Many Thanks,
Mark
I am trying to write code to cycle through rows in an excel spreadsheet and delete the row if the end column is less than 1.
The code does delete the rows correctly however as it is a For x = y to z means that when a row is deleted the z does not reduce.
I tried to fixed this by reducing the z (in this case it is FinalRowFcstSheet) by -1 if a row has been deleted, however the RowNo goes beyond the FinalRowFcstSheet number and seems to continue on till the initial FinalRowFcstSheet value of circa 45,000, I have to stop the code as runs for a very long time.
below is the code is there an easy fix or a different way to achieve what I am trying to do.
Many Thanks,
Mark
Code:
Dim FinalRowFcstSheet As Long
Dim RowNo As Long
RowNo = 2
FinalRowFcstSheet = Worksheets("WkOnWkFcst").Range("b65000").End(xlUp).Row
FinalColumnFcst = Worksheets("WkOnWkFcst").Range("IV1").End(xlToLeft).Column
For RowNo = 2 To FinalRowFcstSheet
If Worksheets("WkOnWkFcst").Cells(RowNo, FinalColumnFcst).Value < 0.5 Then
FinalRowFcstSheet = FinalRowFcstSheet - 1
Worksheets("WkOnWkFcst").Rows(RowNo).Delete
RowNo = RowNo - 1
End If
Next RowNo