Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations pierreick on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

MATCH goes wrong 1

Status
Not open for further replies.

GregLocock

Automotive
Apr 10, 2001
23,653
Attached file shows a couple of columns of data . For obscure reasons I want the user to be able to place the data anywhere in the yellow box, as a contiguous column.

Row 7 detects the start of the data, row 8 detects the end. 8 works in one case, not in the other. Why?



Cheers

Greg Locock


New here? Try reading these, they might help FAQ731-376
 
Replies continue below

Recommended for you

Very strange, I think you have found a bug!

On the attached copy of your worksheet I have:
1. Added a helper column (=D16<>0) and done the MATCH on that. That gives the same results as yours, and returns TRUE or FALSE correctly for both columns.
2. Extended the column of numbers in Col D to cover 66 rows. The Match formula now works correctly!

So it seems that =MATCH(TRUE,D16:D167<>0,1) only works if the number of TRUE rows > 65.

I guess the easiest solution would be to use Match to find the first row with data then COUNTIF to find the last.


Doug Jenkins
Interactive Design Services
 
There is a discussion of a different but related problem here:

It seems that Excel's behaviour is erratic for a Match on unsorted data.

Another alternative would be:
=MATCH(1000000,D16:D167,1)+15

which will return the row of the greatest value <= 1000000.


Doug Jenkins
Interactive Design Services
 
If Doug sees a bug that worries me. Should I even peek at the sheet?

(time goes by)

OK I looked, and under Open Office I see the exact same result. I looked at the text of the xlxs file and saw no hidden values for those cells.

I tried a number of things and the more I look at it the more I wonder how this ever works. (ISBLANK, NOT(ISNUMBER)

When I think of array formulas I think of it working as "FOR EACH" array entry, but formulas that work with that should work with it one line at a time and MATCH doesn't.

=MATCH(TRUE,H16<>0,0) fails as does =MATCH(TRUE,H16<>0,1) yet {=MATCH(TRUE,H16:H167<>0,1)+15} does.

Where did this method come from?
 
3DDave, if you add a helper column with H16<>0, which returns TRUE or FALSE for each row, and do the MATCH on that column, it works exactly the same as Greg's formula.

The problem is, using match type = 1 it assumes the data is in ascending order, and it does a binary search. It starts with a cell close to the middle of the range, and if that is past the end of the data it will continue searching down the column until it gets to the last cell where it finds the value is as close to the search value as any other cell it has checked, so it reports that cell as the match.

When the data extends past half way it will continue working down the rows until it gets to the last one with a number, and report that as the match, which is what is wanted in this case.

Doug Jenkins
Interactive Design Services
 
The question I had was how MATCH works as an array function at all, but I guess it internally generates a hidden array that is what is evaluated by the MATCH function rather than expanding that hidden array into a column of it's own values on the sheet. Even then, why isn't that array indexed from row 1 or from the row the function is on?

I suppose that this behavior is why Microsoft has deprecated array formulas in favor of dynamic arrays, but I don't have access to that.

I liked array formulas when they first came out but the number of uses that depend on side-effects suggests it was a bad implementation. For example, it doesn't allow me to sort the hidden array of TRUE/FALSE values, so it's not a first-class capability. It's got some special cases where it works, but not all cases.
 
Um, good, looks like its above my paygrade. Thank you both. Yes I had fiddled with arrays, but they didn't seem to help. As to what the MATCH(TRUE is doing, um, I stole it off the internet!

So what I wanted to do was build an array reference using the two numbers, say front_wheelrate!$C$23:$C$109
name it as 'fwr' and then use INDIRECT(fwr) for various things.

But, the way Excel handles INDIRECT(fwr) is also less than robust. So I can't do what I want, but since I found the above problem it wouldn't have worked in the general case anyway.

The official solution (apparently) is to use a table.

Cheers

Greg Locock


New here? Try reading these, they might help FAQ731-376
 
Greg,

You have DATA in column D below the last visible characters in row 76.

Try Deleting all the rows below the last row of data on the sheet and all the columns to the right of the last column of data on the sheet. I often did this as a matter of course and checked my results using Worksheet.UsedRange by returning the Last Row & Last Column on the sheet.

This has NOTHING to do with the MATCH() function!
Your formula returns 76 as the last row with data.

Skip,

[glasses]Just traded in my OLD subtlety...
for a NUance![tongue]
 
Scattered applause soon increases to a full standing ovation!

Encore Doug, Encore!
 
Greg,

You've got phantom DATA in column D from row 138 and downward.

I modified your formula for rows below row 76...
E77: =MATCH(TRUE,D$16:D77<>0,1)+15
...and copied down in column E in order to discover in what row the data resides.

Skip,

[glasses]Just traded in my OLD subtlety...
for a NUance![tongue]
 
Skip - it is nothing to do with phantom data. If the search column is empty for just over half the length from the bottom the formula returns the row number for the last row in the search range rather than the last row with data.

If you enter =D16<>0 in cell E16, and copy it down to E167, it returns FALSE for all cells from row 77 to 167. Also my suggested alternatives return the right row for the last data row.


Doug Jenkins
Interactive Design Services
 
"If the search column is empty for just over half the length from the bottom the formula returns the row number for the last row in the search range rather than the last row with data."

Yup that seems to be a repeatable 'feature'. Now, OK it is my fault for probably abusing MATCH, and monkey see monkey do is dangerous. IDS's alternative looks good, I'll try that.

Thank you all,

Cheers

Greg Locock


New here? Try reading these, they might help FAQ731-376
 
Doug,

Checked out your statement, "If the search column is empty for just over half the length from the bottom the formula returns the row number for the last row in the search range rather than the last row with data."

And you're correct! I cede to your brilliance regarding a MATCH() search under these conditions.

Skip,

[glasses]Just traded in my OLD subtlety...
for a NUance![tongue]
 
I was going to ask him why the search range was not the range of the data. I suppose that there may be instances where a range of data would logically reside outside of a tabular data set. I was late to the party.

Anyhow good catch.

Skip,

[glasses]Just traded in my OLD subtlety...
for a NUance![tongue]
 
Copy H8, Paste D8

and it works

the mystery deepens!

 
Skip - Ok, so basically I cut and paste a pair of columns that I want to analyse and also plot as XY data, and interpolate some particular points off that curve. So I can display my interpolated points fine, but for prettiness sake I also wanted to put the original curve in. But the original curve is much bigger than the small group of interpolated points, so I wanted to truncate the original pair of columns (manually) so that the displayed data is neater, without having to muck about with axis limits.


But I have realised that there are approximately 2460 alternative ways of doing the same job automagically. So it is now a non problem.

Cheers

Greg Locock


New here? Try reading these, they might help FAQ731-376
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor