I have used logic from other stack exchange problems with a similar issue but I CANNOT figure it out. (good examples looked at here: VBa conditional delete loop not working) I'm sure it is really simple. Why is my code getting stuck in an endless loop here?
I'm just replacing a value and then deleting a range of rows. Any ideas what's wrong? Double loop issue possibly? I've looked at it too long and it all seems logical to me. Any help would be much appreciated.
i = 4
Do While i < 10
j = 0
Do While j < 24
ho = Cells(i, 69 + j)
If 0 < ho < 3 Then
k = Cells(i, 67 + j)
Cells(i - 1, 67 + j) = k
Range(Cells(i, 66 + j), Cells(i, 69 + j)).Delete (xlShiftUp)
Else
j = j + 4
End If
Loop
i = i + 1
Loop
jwill be stuck at a static value and never reach 24.DoEventsandDebug.Print jbetween the statementEnd IfandLoop. Observe the valuejin the Immediate Windowi = 10,000then iteratei = i - 1. this is because when u delete rows, the row number changes. otherwise u have to consider the change in row number for the bottom data in ur row deletion.If 0 < ho < 3 Thenis interpreted as either (I can't remember which it will be)If (0 < ho) < 3 ThenorIf 0 < (ho < 3) Then. In either case, it is comparing True/False with a number. You probably want to change that statement toIf 0 < ho And ho < 3 Then. (I don't know whether this is a cause of your problem, but it will certainly mean it isn't doing what you expect.)