+ Reply to Thread
Results 1 to 15 of 15

How easely prevent problems with MATCH on a array with one value

  1. #1
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,435

    How easely prevent problems with MATCH on a array with one value

    If I try the match function on an array of 1 value, Excel returns always #N/A. Why?
    If you match on a range of 1 cell Excel does well.

    This is very annoying when needed in extended formulas (when you don't know the size of the array before).
    I did come up with a workaround for this by adding a dummy value behind the array with VSTACK,
    but I don't find that elegant at all.

    Does anyone know a better solution?
    See attachment with working and not working examples and my workaround solution.

    Does anyone have better ideas?
    Attached Files Attached Files
    Last edited by HansDouwe; 07-15-2023 at 05:06 PM. Reason: Solution corrected

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,971

    Re: How easely prevent problems with MATCH on a array with one value

    Not an answer, but I have got round it like this before:

    =INDEX(array,1)

    Don't know why it happens.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,435

    Re: How easely prevent problems with MATCH on a array with one value

    =Index(arrray,1)?

    This reruns always the first value of the array, but that is not what I want.

    If the array contains 1 value it should return 1 or #N/A. If the array contains 2 values it should return 1, 2 or #N/A etcetera.
    Last edited by HansDouwe; 07-15-2023 at 05:22 PM.

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,971

    Re: How easely prevent problems with MATCH on a array with one value

    You said an array of one value returns N/A with MATCH. I have found the same, but indexing the array first as I showed gets round it.

    I think you need to give a more detailed example of what you mean.

  5. #5
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,435

    Re: How easely prevent problems with MATCH on a array with one value

    If an array contains 1 value the formula =MATCH(value, array) returns always #N/A.

    What I want a formula that in case of 1 value returns 1 or #N/A and in case of 2 values returns 1, 2 or #N/A and so on.
    I need this in extended formulas.

    I would expect the formula =MATCH(value, array) to do that. But it does not do that if the array consists of 1 value.
    As far I can tell, The MATCH formula works only correct if an array have at least 2 values.
    I find that very strange, because the formula works well on a range of 1 cell.

    The formula =MATCH(value,VSTACK(array,"") does the job correct if the array has only 1 value, but I think that's a crazy solution.
    Last edited by HansDouwe; 07-15-2023 at 05:46 PM.

  6. #6
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,435

    Re: How easely prevent problems with MATCH on a array with one value

    CrosspostingI also tried posting this question at https://techcommunity.microsoft.com/.

    I thought that went well, but now I can't find my own post.
    I don't know if I did something wrong when posting or when looking back.
    Pff.

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,464

    Re: How easely prevent problems with MATCH on a array with one value

    For what it’s worth, you don't need to stack the null value. This works for me:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Slightly more aesthetically pleasing, I guess, and you can drag it down.

    1 =MATCH(6,VSTACK(A$2:A2*2))
    2 =MATCH(6,VSTACK(A$2:A3*2))
    3 =MATCH(6,VSTACK(A$2:A4*2))
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,464

    Re: How easely prevent problems with MATCH on a array with one value

    You only appear to have one post on that forum: https://techcommunity.microsoft.com/...ser-id/1427699

  9. #9
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,435

    Re: How easely prevent problems with MATCH on a array with one value

    Thanks Trevor,
    That's a lot better than my solution. Despite the use of VSTACK, there is no stacked value, so a wrong result can never arise.

    I keep finding it very strange that I also have to use VSTACK with the match function on an array, when the array can consist of 1 value.

    The fact that that is necessary is a bug in the MATCH function for me:
    I can't find anywhere that an array of 1 value should not be allowed as the second parameter in a MATCH function.

    Problem is solved for me.
    Last edited by HansDouwe; 07-15-2023 at 08:53 PM.

  10. #10
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,971

    Re: How easely prevent problems with MATCH on a array with one value

    I've looked at your attachment and it's a bit different (but similar) to an issue I found. INDEX won't work in your case, but it did on mine (but I can't find the problem I was working on when it happened).

  11. #11
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,464

    Re: How easely prevent problems with MATCH on a array with one value

    @Hans: You're welcome. Thanks for the rep.

  12. #12
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,063

    Re: How easely prevent problems with MATCH on a array with one value

    Try XMATCH...

    =XMATCH(6,2*A$2:A2,0)

    reurns 1 in all 3 instances, but ONLY with an exact match. If you want the ascending series of answers (1,2,3), use:

    =XMATCH(6,2*A$2:A2,1,-1)
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

  13. #13
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,063

    Re: How easely prevent problems with MATCH on a array with one value

    I'm getting forgetful... for NUMBERS you can also use =MATCH(6,2*A$2:A2+{0})

    and for TEXT +{""}

  14. #14
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,435

    Re: How easely prevent problems with MATCH on a array with one value

    @Ali, thanks for looking.

  15. #15
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,435

    Re: How easely prevent problems with MATCH on a array with one value

    @Glenn,

    Yes XMATCH does the job, exactly as you expect it . You just have to know. Thanks.

    I will keep the other option of post #13 in mind for use in Excel versions before 2021 (beacause there is no XMATCH and there is no VSTACK).

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Problems with INDEX, MATCH, MATCH returning incorrect values
    By Paul103 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-03-2018, 05:16 PM
  2. Replies: 5
    Last Post: 02-22-2018, 01:47 AM
  3. Problems applying INDEX-MATCH-MATCH function on other data
    By LennartB in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 05-13-2015, 05:33 AM
  4. [SOLVED] Array Match and Return value upon multiple array match criteria
    By VegetaOSX in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-05-2015, 05:50 AM
  5. Replies: 6
    Last Post: 04-30-2014, 02:42 AM
  6. Logic check to prevent evaluation of an array formula
    By TheRobsterUK in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 03-12-2014, 11:24 AM
  7. [SOLVED] Problems Converting 1-D Array to 2-D Array
    By ExcelMonkey in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-27-2005, 08:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1