View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
dq dq is offline
external usenet poster
 
Posts: 46
Default Modifying For Loop

Dave,

The problem is that you are changing MyCell twice in the loop, once by
the loop itself
For Each myCell In Range("C1:C65536")
and once by using
Set myCell = myCell(myRowCount + 1, 1)
I think if you rewrite your loop like shown below, it should work

DQ

Dim myRowCount, myCount As Variant
myRowCount = 0
myCount = 0

myRowCount = 0
Do While myRowCount <= 65535
myRowCount = myRowCount + 1
Set myCell = Cells(myRowCount, 3)
StartRow = myCell.Row
If myCell.Value < myCell(2, 1).Value Then
' 'Monkey business here bumps myCount upwards
myRowCount = myCount + 1
myCount = 0
Else
myCount = myCount + 1
End If
Loop