Thread
:
Next not incrementing
View Single Post
#
10
Posted to microsoft.public.excel.programming
Don Guillett[_4_]
external usenet poster
Posts: 2,337
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!
Reply With Quote
Don Guillett[_4_]
View Public Profile
Find all posts by Don Guillett[_4_]