I followed Tom's suggestion and created the following procedure which also
checks for Beginning and EndOfRange (remember Clipper's BOF() and EOF() ??).
The code works great.
The thing is I nedd to use it to search dates. I found that only when
searching dates formatted as numbers I am able to MATCH correctly, because
formatted dates fall out of sequence (unless they are ANSI dates but who uses
them). If only there was a way to avoid formatting the range back and
forth... Can you suggest anything?? Is there a way to MATCH against the
underlying date number and not the visible date format?
Private Sub test()
Dim res As Variant
aaa = "10/1/06"
bbb = Val(Format(aaa, "#"))
cRange = "a5:a22"
Range(cRange).NumberFormat = "#"
nFirstRow = Range(cRange).Row
nLastRow = Range(cRange).Rows.Count + nFirstRow - 1
nColumn = Range(cRange).Column
res = Application.Match(bbb, Range(cRange), 0) ' search for exact match '
If Not IsError(res) Then
Cells(res + nFirstRow - 1, nColumn).Select ' compensate for first line
offset '
MsgBox ("Exact match")
Else
res = Application.Match(bbb, Range(cRange), 2) ' search for greater '
If Not IsError(res) Then
Cells(res + nFirstRow, nColumn).Select
If ActiveCell.Row > nLastRow Then ' search value is greater than any
value in range'
ActiveCell.Offset(-1, 0).Select
MsgBox ("End of range reached - Positioning active cell to last row")
Else
MsgBox ("Greater value found")
End If
Else ' value is less than any value in range '
Cells(nFirstRow, nColumn).Select
MsgBox ("Beginning of range reached - Positioning active cell to first
row")
End If
End If
Range(cRange).NumberFormat = "ddd dd/mm/yy"
End Sub