ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Finding a date rather than text (https://www.excelbanter.com/excel-programming/381696-finding-date-rather-than-text.html)

Fred Smith

Finding a date rather than text
 
I have a column of dates. I want to find the cell which contains the date
1/1/2003. The code I tried is:

Set Foundcell = Range("A:A").Find(What:="1/1/2003")

Unfortunately, because the dates are in reverse chronological order, the Find
stops at 11/1/2003.

What code do I need to get Excel to check for a date, rather than a string? I
tried What:=#1/1/2003# but that didn't help.

--
Thanks,
Fred




Tom Ogilvy

Finding a date rather than text
 
Dim rng as Range, FoundCell as Range
Dim res as Variant
set rng = Columns(1).Cells
res = Application.Match(clng(DateValue("1/1/2003")),rng,0)
if not iserror(res) then
set FoundCell = rng(res)
Else
msgbox "Not found"
exit sub
end if

msgbox "Found at " & foundcell.Address

--
Regards,
Tom Ogilvy


"Fred Smith" wrote in message
...
I have a column of dates. I want to find the cell which contains the date
1/1/2003. The code I tried is:

Set Foundcell = Range("A:A").Find(What:="1/1/2003")

Unfortunately, because the dates are in reverse chronological order, the
Find stops at 11/1/2003.

What code do I need to get Excel to check for a date, rather than a
string? I tried What:=#1/1/2003# but that didn't help.

--
Thanks,
Fred






Fred Smith

Finding a date rather than text
 
Thanks, Tom. Just what I needed.

--
Regards,
Fred


"Tom Ogilvy" wrote in message
...
Dim rng as Range, FoundCell as Range
Dim res as Variant
set rng = Columns(1).Cells
res = Application.Match(clng(DateValue("1/1/2003")),rng,0)
if not iserror(res) then
set FoundCell = rng(res)
Else
msgbox "Not found"
exit sub
end if

msgbox "Found at " & foundcell.Address

--
Regards,
Tom Ogilvy


"Fred Smith" wrote in message
...
I have a column of dates. I want to find the cell which contains the date
1/1/2003. The code I tried is:

Set Foundcell = Range("A:A").Find(What:="1/1/2003")

Unfortunately, because the dates are in reverse chronological order, the Find
stops at 11/1/2003.

What code do I need to get Excel to check for a date, rather than a string? I
tried What:=#1/1/2003# but that didn't help.

--
Thanks,
Fred









All times are GMT +1. The time now is 12:28 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com