#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default Find date

Hi All,

I have two ranges of dates, both one's width is one column in which dates
are created by =DATE() functions. In the first range cells are formatted like
"yyyy.mm.dd", in the 2nd one like "mmmm d.".
In a macro I have a date variable DateToFind created by a DateSerial()
function.

I used
Range("first range").Find(What:=DateToFind ).Row 0

to check if DateToFind is included in first range and it worked.
For the second range it gave a Type mismatch error, and i had to modify the
Find line like this to make it work:
Range("first range").Find(What:=Format(DateToFind , "mmmm d.")).Row 0

I can't find out what is the cause of this error, because both the range I
search in and the value I want to find are real Excel date values (numbers),
only the display format is different. In other words: why does Excel find the
numeric value of the date in the first range and why the display format
string in the second string?

--
Regards!
Stefi

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Find date

Stefi,

The Find method uses the worksheet find dialog, which is set up to find the
displayed value, not the underlying value.

And, in case the formatting is ever changed, it is better to use code that
reads the formatting prior to the Find:

Range("first range").Find(Format(DateToFind, Range("first
range").Cells(1,1).NumberFormat)).Row 0

HTH,
Bernie
MS Excel MVP


"Stefi" wrote in message
...
Hi All,

I have two ranges of dates, both one's width is one column in which dates
are created by =DATE() functions. In the first range cells are formatted
like
"yyyy.mm.dd", in the 2nd one like "mmmm d.".
In a macro I have a date variable DateToFind created by a DateSerial()
function.

I used
Range("first range").Find(What:=DateToFind ).Row 0

to check if DateToFind is included in first range and it worked.
For the second range it gave a Type mismatch error, and i had to modify
the
Find line like this to make it work:
Range("first range").Find(What:=Format(DateToFind , "mmmm d.")).Row 0

I can't find out what is the cause of this error, because both the range I
search in and the value I want to find are real Excel date values
(numbers),
only the display format is different. In other words: why does Excel find
the
numeric value of the date in the first range and why the display format
string in the second string?

--
Regards!
Stefi



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default Find date

Very tricky, thanks, Bernie!
--
Regards!
Stefi



€˛Bernie Deitrick€¯ ezt Ć*rta:

Stefi,

The Find method uses the worksheet find dialog, which is set up to find the
displayed value, not the underlying value.

And, in case the formatting is ever changed, it is better to use code that
reads the formatting prior to the Find:

Range("first range").Find(Format(DateToFind, Range("first
range").Cells(1,1).NumberFormat)).Row 0

HTH,
Bernie
MS Excel MVP


"Stefi" wrote in message
...
Hi All,

I have two ranges of dates, both one's width is one column in which dates
are created by =DATE() functions. In the first range cells are formatted
like
"yyyy.mm.dd", in the 2nd one like "mmmm d.".
In a macro I have a date variable DateToFind created by a DateSerial()
function.

I used
Range("first range").Find(What:=DateToFind ).Row 0

to check if DateToFind is included in first range and it worked.
For the second range it gave a Type mismatch error, and i had to modify
the
Find line like this to make it work:
Range("first range").Find(What:=Format(DateToFind , "mmmm d.")).Row 0

I can't find out what is the cause of this error, because both the range I
search in and the value I want to find are real Excel date values
(numbers),
only the display format is different. In other words: why does Excel find
the
numeric value of the date in the first range and why the display format
string in the second string?

--
Regards!
Stefi



.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Find date

I think she could have done it this way as well...

Range("first range").Find(What:=DateToFind, LookIn:=xlFormulas).Row 0

--
Rick (MVP - Excel)



"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
Stefi,

The Find method uses the worksheet find dialog, which is set up to find
the displayed value, not the underlying value.

And, in case the formatting is ever changed, it is better to use code that
reads the formatting prior to the Find:

Range("first range").Find(Format(DateToFind, Range("first
range").Cells(1,1).NumberFormat)).Row 0

HTH,
Bernie
MS Excel MVP


"Stefi" wrote in message
...
Hi All,

I have two ranges of dates, both one's width is one column in which dates
are created by =DATE() functions. In the first range cells are formatted
like
"yyyy.mm.dd", in the 2nd one like "mmmm d.".
In a macro I have a date variable DateToFind created by a DateSerial()
function.

I used
Range("first range").Find(What:=DateToFind ).Row 0

to check if DateToFind is included in first range and it worked.
For the second range it gave a Type mismatch error, and i had to modify
the
Find line like this to make it work:
Range("first range").Find(What:=Format(DateToFind , "mmmm d.")).Row 0

I can't find out what is the cause of this error, because both the range
I
search in and the value I want to find are real Excel date values
(numbers),
only the display format is different. In other words: why does Excel find
the
numeric value of the date in the first range and why the display format
string in the second string?

--
Regards!
Stefi



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default Find date

Hi Rick,

I tried your solution but it didn't work. To say the truth, I had to add
Lookin:=xlValues to Bernie's solution to make it work safely.

--
Regards!
Stefi



€˛Rick Rothstein€¯ ezt Ć*rta:

I think she could have done it this way as well...

Range("first range").Find(What:=DateToFind, LookIn:=xlFormulas).Row 0

--
Rick (MVP - Excel)



"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
Stefi,

The Find method uses the worksheet find dialog, which is set up to find
the displayed value, not the underlying value.

And, in case the formatting is ever changed, it is better to use code that
reads the formatting prior to the Find:

Range("first range").Find(Format(DateToFind, Range("first
range").Cells(1,1).NumberFormat)).Row 0

HTH,
Bernie
MS Excel MVP


"Stefi" wrote in message
...
Hi All,

I have two ranges of dates, both one's width is one column in which dates
are created by =DATE() functions. In the first range cells are formatted
like
"yyyy.mm.dd", in the 2nd one like "mmmm d.".
In a macro I have a date variable DateToFind created by a DateSerial()
function.

I used
Range("first range").Find(What:=DateToFind ).Row 0

to check if DateToFind is included in first range and it worked.
For the second range it gave a Type mismatch error, and i had to modify
the
Find line like this to make it work:
Range("first range").Find(What:=Format(DateToFind , "mmmm d.")).Row 0

I can't find out what is the cause of this error, because both the range
I
search in and the value I want to find are real Excel date values
(numbers),
only the display format is different. In other words: why does Excel find
the
numeric value of the date in the first range and why the display format
string in the second string?

--
Regards!
Stefi



.

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
Julian date - find next highest date/number jchick0909 Excel Worksheet Functions 1 March 20th 08 11:38 PM
Find the date of the coming up Saturday given the current date. Michael Ermino Excel Worksheet Functions 4 April 11th 07 02:48 AM
xls vba find method to find row that contains the current date RCranston Excel Programming 3 March 28th 07 03:59 PM
Using variables to make a date and using find method to find that. KyWilde Excel Programming 2 April 21st 05 09:43 PM
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 10:11 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"