View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
Don Guillett[_4_] Don Guillett[_4_] is offline
external usenet poster
 
Posts: 2,337
Default Next not incrementing

or from anwhere in the workbook with NO selections.

Sub extractbydate2()
With Sheets("b")
For i = 2 To .Cells(2, 2).End(xlDown).Row
If .Cells(i, 2) [a!a2] And .Cells(i, 2) < [a!b2] Then _
.Range(.Cells(i, 2), .Cells(i, 3)).Copy _
Sheets("a").Cells(Cells(65536, 1).End(xlUp).Row + 1, 1)
Next i
End With
End Sub

--
Don Guillett
SalesAid Software

"davegb" wrote in message
oups.com...
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!