View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Trouble with Find Method

Also, you have a with statement but don't use it - instead, the unqualifed
Cells searches the entire sheet. And the unqualified Cells(796) is
probably not what you think. From the immediate window:

? cells(796).Address
$AB$4


With Activesheet.Columns(1)
set Current = .Cells.Find(What:=ThisDate, _
After:=.Cells(796), LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
End With
if not current is nothing then
set current = current.Offset(0, 4)
else
msgbox "Not found"
end if

--
Regards,
Tom Ogilvy


"Alan M" wrote in message
...
I am using the following to find today's date in a column containing
dates for every day of the year.

I have defined the serxh target using the Dim ThisDate declaration but

when
I run the code , for some unexpklained reason , I receive an error message
saying that the object is not defined.

Can you shed any light on this simple problem please?





Dim ThisDate As Range
Dim I As Range
Dim Current As Range

Sheets(2).Unprotect

Set ThisDate = Range("B3") 'Cell contains today's date

With ActiveSheet.Range("A:A")

' Searches for todays date in Column A

Cells.Find(What:=ThisDate, _
After:=Cells(796), LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext,

_
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(0, 4).Select
Set Current = Selection