View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
davegb davegb is offline
external usenet poster
 
Posts: 573
Default Next not incrementing

The final version is:

Sub ExtractbyDate()
Dim i As Integer
dtBeginDate = Sheets("A").Range("A2").Value
dtEndDate = Worksheets("A").Range("B2").Value
iCurRow = 5
Sheets("B").Select
For i = 2 To Sheets("B").Cells(2, "b").End(xlDown).Row
If Cells(i, 2).Value dtBeginDate _
And Cells(i, 2).Value < dtEndDate Then
strID = Cells(i, 2).Offset(0, -1).Value
curCost = Cells(i, 2).Offset(0, 1).Value
Sheets("A").Cells(iCurRow, 1) = strID
Sheets("A").Cells(iCurRow, 2) = curCost
iCurRow = iCurRow + 1

End If
Next
If iCurRow = 5 Then
MsgBox "There were no matching dates", vbOKOnly
End If

I had to put in the "Sheets ("B").Select" to get it to run if I was in
sheet A when I ran it. I thought putting in the "For i = 2 To
Sheets("B").Cells(2, "b").End(xlDown).Row" would help it find Sheet B,
but it didn't.
At least it runs.
Thanks for all the help!