Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 623
Default 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



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 623
Default 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







Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding a Date 90 days previous to present date Vinod Excel Worksheet Functions 2 June 15th 09 01:18 PM
Finding text in a cell and returning a value based on that text [email protected] Excel Discussion (Misc queries) 5 January 10th 07 06:01 PM
finding a date/time in a list that is closest to an existing date/ Jamie Excel Discussion (Misc queries) 1 May 27th 06 08:54 PM
Finding the Monday date based on a different date in same week dandiehl Excel Worksheet Functions 4 April 11th 06 06:03 PM
Finding Specific Text in a Text String Peter Gundrum Excel Worksheet Functions 9 April 10th 05 07:21 PM


All times are GMT +1. The time now is 04:59 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"