View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
WhytheQ WhytheQ is offline
external usenet poster
 
Posts: 246
Default FIND DATE xlLastRow and searchdirection

I think you may need to use the FindNext method! There is a good
example in the online help which might get you started:

'=======================================
This example finds all cells in the range A1:A500 that contain the
value 2 and changes their values to 5.

With Worksheets(1).Range("a1:a500")
Set c = .Find(2, lookin:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
c.Value = 5
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address < firstAddress
End If
End With
=======================================

.....so the above example loops down to the last instance of 2 and
changes it to a 5: the way the above loops down through the values to
find the last instance of 2 is the bit I reckon you might find useful.

Rgds
J




On Oct 18, 1:52 pm, "Baine" wrote:
Sub FindDates()
On Error GoTo errorHandler
Dim startDate As String
Dim stopDate As String
Dim startRow As Integer
Dim stopRow As Integer

startDate = InputBox("Enter the Start Date: (mm/dd/yy)")
If startDate = "" Then End
stopDate = InputBox("Enter the Stop Date: (mm/dd/yy)")
If stopDate = "" Then End
startDate = Format(startDate, "mm/dd/yy")
stopDate = Format(stopDate, "mm/dd/yy")
startRow = Worksheets("MASTER").Columns("C").Find(startDate, _
LookIn:=xlValues, lookat:=xlWhole).Row
stopRow = Worksheets("MASTER").Columns("C").Find(stopDate, _
LookIn:=xlValues, lookat:=xlWhole).Row
Worksheets("MASTER").Range("B" & startRow & ":AZ" & stopRow).Copy _
Destination:=Worksheets("Sheet3").Range("A1")
End
errorHandler:
MsgBox "There has been an error: " & Error() & Chr(13) _
& "Ending Sub.......Please try again", 48
End Sub

My date is in column C. I sometimes have more than one with the same date.
I select the dates with the input box and it gets all of the rows I want
except if there is more than one with the same stopDate. The sheet has been
sorted on the date column. I thought if I could search from the bottom up
it would solve my problem. Could I get some help with the code to do a
seartch from the bottom up?