Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default Error using MATCH with dates in variables


If I match a named range ("Criteria_12") I get the correct result but if I
assign the cell value to a variable I get an #N/A error. It makes no
difference if I declare (DIM) the variables dt or curr_date.

Why?

TIA



dt = Range("Criteria_12")
curr_date = DateSerial(Year(dt), Month(dt), Day(dt))

' This works OK .......

Range("A5") = Application.Match(Range("Criteria_12"), Range("1:1"), 0)

' These return error conditions ....WHY?

Range("A6") = Application.Match(dt, Range("1:1"), 0)
Range("A7") = Application.Match(curr_date, Range("1:1"), 0)
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default Error using MATCH with dates in variables

Solved it!

Range("A6") = Application.Match(Clng(dt), Range("1:1"), 0)

"Toppers" wrote:


If I match a named range ("Criteria_12") I get the correct result but if I
assign the cell value to a variable I get an #N/A error. It makes no
difference if I declare (DIM) the variables dt or curr_date.

Why?

TIA



dt = Range("Criteria_12")
curr_date = DateSerial(Year(dt), Month(dt), Day(dt))

' This works OK .......

Range("A5") = Application.Match(Range("Criteria_12"), Range("1:1"), 0)

' These return error conditions ....WHY?

Range("A6") = Application.Match(dt, Range("1:1"), 0)
Range("A7") = Application.Match(curr_date, Range("1:1"), 0)

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,311
Default Error using MATCH with dates in variables

What does the "CLng" do?


"Toppers" wrote in message
...
Solved it!

Range("A6") = Application.Match(Clng(dt), Range("1:1"), 0)

"Toppers" wrote:


If I match a named range ("Criteria_12") I get the correct result but if
I
assign the cell value to a variable I get an #N/A error. It makes no
difference if I declare (DIM) the variables dt or curr_date.

Why?

TIA



dt = Range("Criteria_12")
curr_date = DateSerial(Year(dt), Month(dt), Day(dt))

' This works OK .......

Range("A5") = Application.Match(Range("Criteria_12"), Range("1:1"),
0)

' These return error conditions ....WHY?

Range("A6") = Application.Match(dt, Range("1:1"), 0)
Range("A7") = Application.Match(curr_date, Range("1:1"), 0)



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default Error using MATCH with dates in variables

Converts date to Long (Integer) which is how the dates are held (as you
know!) so the MATCH now works..

"PCLIVE" wrote:

What does the "CLng" do?


"Toppers" wrote in message
...
Solved it!

Range("A6") = Application.Match(Clng(dt), Range("1:1"), 0)

"Toppers" wrote:


If I match a named range ("Criteria_12") I get the correct result but if
I
assign the cell value to a variable I get an #N/A error. It makes no
difference if I declare (DIM) the variables dt or curr_date.

Why?

TIA



dt = Range("Criteria_12")
curr_date = DateSerial(Year(dt), Month(dt), Day(dt))

' This works OK .......

Range("A5") = Application.Match(Range("Criteria_12"), Range("1:1"),
0)

' These return error conditions ....WHY?

Range("A6") = Application.Match(dt, Range("1:1"), 0)
Range("A7") = Application.Match(curr_date, Range("1:1"), 0)




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,311
Default Error using MATCH with dates in variables

Thanks. While playing around with your code (before you solved it, of
course), I noticed that I could set the variable to equal the value of the
date, as in:
=VALUE(TODAY())
In today's date, this gave me 39232. Using that set to a variable instead
of the "dt" variable allowed the match function to match properly. So I
assumed that must be the issue, but I didn't know how to correct it. Thanks
for the info. Another something new learned today.

Regards,
Paul


"Toppers" wrote in message
...
Converts date to Long (Integer) which is how the dates are held (as you
know!) so the MATCH now works..

"PCLIVE" wrote:

What does the "CLng" do?


"Toppers" wrote in message
...
Solved it!

Range("A6") = Application.Match(Clng(dt), Range("1:1"), 0)

"Toppers" wrote:


If I match a named range ("Criteria_12") I get the correct result but
if
I
assign the cell value to a variable I get an #N/A error. It makes no
difference if I declare (DIM) the variables dt or curr_date.

Why?

TIA



dt = Range("Criteria_12")
curr_date = DateSerial(Year(dt), Month(dt), Day(dt))

' This works OK .......

Range("A5") = Application.Match(Range("Criteria_12"),
Range("1:1"),
0)

' These return error conditions ....WHY?

Range("A6") = Application.Match(dt, Range("1:1"), 0)
Range("A7") = Application.Match(curr_date, Range("1:1"), 0)






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
INDEX - MATCH with three variables Pops Jackson Excel Worksheet Functions 3 July 20th 07 06:09 PM
Error in setting formula (Match) with dynamic variables John Wong[_2_] Excel Programming 2 November 8th 06 04:35 PM
Please Help! vlookup & match with multiple variables ivygirl Excel Worksheet Functions 2 January 7th 06 09:46 AM
Finding two variables on the same row to match function Werner[_26_] Excel Programming 2 July 11th 05 09:37 PM
Index Match With 3 Variables Scooterdog Excel Worksheet Functions 5 January 2nd 05 07:05 PM


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

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

About Us

"It's about Microsoft Excel"