Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Find a date in a range

Hello

I've an excep application in VSTO.
In some point i want to be able to find if a perticular date is in a range.

my code is:

rng = rng.Find( date,
Type.Missing,
Excel.XlFindLookIn.xlFormulas,
Type.Missing,
Type.Missing,
Excel.XlSearchDirection.xlNext,
Type.Missing,
Type.Missing,
Type.Missing);

where rng is a well defined Excel.Range(i've checked it) and date is my
DateTime object to find.

This method find always returns null... i guess that's hapenning 'cause
diferences
in date formats from c# and Excel.

Can you help me here... how can i search a range for a date?!

i'm loosing my mind over here

best regards

Jorge
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,420
Default Find a date in a range

Try casting date to a long,Excel stores dates as long.

--
__________________________________
HTH

Bob

"Jorge Ribeiro" wrote in message
...
Hello

I've an excep application in VSTO.
In some point i want to be able to find if a perticular date is in a
range.

my code is:

rng = rng.Find( date,
Type.Missing,
Excel.XlFindLookIn.xlFormulas,
Type.Missing,
Type.Missing,
Excel.XlSearchDirection.xlNext,
Type.Missing,
Type.Missing,
Type.Missing);

where rng is a well defined Excel.Range(i've checked it) and date is my
DateTime object to find.

This method find always returns null... i guess that's hapenning 'cause
diferences
in date formats from c# and Excel.

Can you help me here... how can i search a range for a date?!

i'm loosing my mind over here

best regards

Jorge



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Find a date in a range

SOLVED:
I first change numberFormat of range to General and then run find method
(didn't find any better way)
Here's my code: input are rng (Range) anda date (date to find)

object oldFormat = rng.NumberFormat;
rng.NumberFormat = "General";
Excel.Range result = rng.Find(date.ToOADate(),
Type.Missing,
Excel.XlFindLookIn.xlFormulas,
Type.Missing,
Type.Missing,
Excel.XlSearchDirection.xlNext,
Type.Missing,
Type.Missing,
Type.Missing);
rng.NumberFormat = oldFormat;

Thanx anyway

Jorge

"Jorge Ribeiro" wrote:

Hello

I've an excep application in VSTO.
In some point i want to be able to find if a perticular date is in a range.

my code is:

rng = rng.Find( date,
Type.Missing,
Excel.XlFindLookIn.xlFormulas,
Type.Missing,
Type.Missing,
Excel.XlSearchDirection.xlNext,
Type.Missing,
Type.Missing,
Type.Missing);

where rng is a well defined Excel.Range(i've checked it) and date is my
DateTime object to find.

This method find always returns null... i guess that's hapenning 'cause
diferences
in date formats from c# and Excel.

Can you help me here... how can i search a range for a date?!

i'm loosing my mind over here

best regards

Jorge

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
Find Last cell in Range when range is date format default105 Excel Discussion (Misc queries) 5 July 7th 09 03:11 PM
Find within Date Range MrRJ Excel Discussion (Misc queries) 4 November 24th 08 06:56 PM
Find by date range Duncan[_5_] Excel Programming 1 April 12th 06 05:26 PM
How to find date in a range? hideki[_21_] Excel Programming 1 November 26th 05 04:16 AM
Find date and copy range based on that date avzundert Excel Programming 2 November 25th 04 10:31 AM


All times are GMT +1. The time now is 09:30 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"