Finding exact date

A

Alex

I am using the following line of code to find a date formatted cell in range
b3:ab300 that matches the content of the date formatted cell in H8 in the
worksheet "Import Macros". The problem that the date 1/1/08 is coming up as
a match to the cell containing 11/1/08 and 2/1/08 shows as matching 12/1/08.
How can I change it to an exact date match? Thanks much.

Set FoundCell = .Range("b3:ab300").Find(what:=Worksheets("Import
Macros").Range("h8").Value)
 
S

sebastienm

Hi,
When using Range.Find, some of the parameters of the Find method, if not
explicitely used, keep their values from the previous use of FInd (even from
the user doing Edit>Find). See online doc:
"The settings for LookIn, LookAt, SearchOrder, and MatchByte are saved each
time you use this method. If you don’t specify values for these arguments the
next time you call the method, the saved values are used"

In your case, it seems like the Find is looking at the part of the cell
while you want it to match the whole cell. That is, try using the
parameter/value:
LookAt:=xlWhole

(also check the other parameters eg: Lookin,...)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top