Find a date in a range

J

Jorge Ribeiro

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
 
J

Jorge Ribeiro

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
 

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