I am looking for some help regarding my For Each loop in Excel VBA.
Set ListofCells = Range(ActiveCell, Range("C12:C9999").Find("!!End Measures!!"))
For Each SingleCell In ListofCells
If ActiveCell.Value = "!!End Measures!!" Then
ActiveCell.Offset(1, 0).Select
Exit For
ElseIf ActiveCell.Value = "" Then
ActiveCell.EntireRow.Delete
End If
Next SingleCell
For some reason this likes to exit the loop early for, as far as I can tell, absolutely no reason. In my spreadsheet I'm looking to delete any unused rows from the ActiveCell down to where the entry-area ends, which I have denoted as "!!End Measures!!". I have also tried:
Set ListofCells = Range(ActiveCell, ActiveCell.End(xlDown))
and it as the same behavior. Ending the loops many rows earlier than expected.
If I put 4 of these loops in a row then it works as intended....but I'm hoping to find out why this might be exiting early instead of having to do something weird like looping this 4 or 5 times.
Any help is greatly appreciated and if I can answer any questions or provide any more information I'd be happy to.