K
katem
OK, this is a strange one. I'm trying to use application.match to
find a value in an array and it's giving me weird results. I'm
reading in a date as the lookup value (7/06/2007 0:13) and it's
looking through an array full of dates (sorted in ascending order) to
find the nearest lowest value:-
matchArray() =
Worksheets("Adamstown").Range("a2:a1027").Value
startArray = WorksheetFunction.Match(controlArray(i, 2),
matchArray, -1)
however, no matter what the lookup value is (in controlArray(i,2))
startArray always seems to be 440 (which isn't the right answer (440
is a date of 9/06/2007 23:56 - this is the last record for the day).
The correct answer is 2. I've input
(the dates range from 7/06/2007 0:03 to 13/06/2007 23:53) (Australian
Date System)
Can anyone help me understand why this doesn't work & how I can fix
it. I've got around it by using the match function on the worksheet
(which is giving me the correct answer) and reading this number into
startArray. However, this is an ugly solution and I'd prefer if it
didn't have to run this way.
I've tested it with different values, below and above the 9/06/2007
23:56 and the answer is always 440. If the search value is outside
the lookup range, I'm still getting 440.
i've also tried both the worksheet.match and application.match
functions, both give the same result.
If someone can give me a pointer, I can upload the file somewhere it
can be looked at, if this helps.
Thanks for your help!
Kate
find a value in an array and it's giving me weird results. I'm
reading in a date as the lookup value (7/06/2007 0:13) and it's
looking through an array full of dates (sorted in ascending order) to
find the nearest lowest value:-
matchArray() =
Worksheets("Adamstown").Range("a2:a1027").Value
startArray = WorksheetFunction.Match(controlArray(i, 2),
matchArray, -1)
however, no matter what the lookup value is (in controlArray(i,2))
startArray always seems to be 440 (which isn't the right answer (440
is a date of 9/06/2007 23:56 - this is the last record for the day).
The correct answer is 2. I've input
(the dates range from 7/06/2007 0:03 to 13/06/2007 23:53) (Australian
Date System)
Can anyone help me understand why this doesn't work & how I can fix
it. I've got around it by using the match function on the worksheet
(which is giving me the correct answer) and reading this number into
startArray. However, this is an ugly solution and I'd prefer if it
didn't have to run this way.
I've tested it with different values, below and above the 9/06/2007
23:56 and the answer is always 440. If the search value is outside
the lookup range, I'm still getting 440.
i've also tried both the worksheet.match and application.match
functions, both give the same result.
If someone can give me a pointer, I can upload the file somewhere it
can be looked at, if this helps.
Thanks for your help!
Kate