+ Reply to Thread
Results 1 to 23 of 23

How to Use array match function in a distance matrix

  1. #1
    Registered User
    Join Date
    03-20-2018
    Location
    INDIA
    MS-Off Ver
    2016
    Posts
    11

    How to Use array match function in a distance matrix

    There are 8 cities in the country of Eight, A, B, C, D, E, F, G and H. Mr. Z decides to visit each city in his car starting from A. His planned itinerary is
    A-->B-->C-->D-->E-->F-->G-->H.
    The distance between the cities is given in Table I


    Table I
    Distance
    A B C D E F G H
    A 0 200
    B 200 0 350
    C 350 0 500
    D 500 0 250
    E 250 0 850
    F 850 0 1250
    G 1250 0 150
    H 150 0



    Write a formula which takes the number of kms that Mr. Z has travelled from A as the input and displays the name of the city which is nearest to that point.

    Mr. Z will enter the number of kms he has travelled from A in cell D30 and the name of the city nearest to the point will be displayed in E30[PHP][PHP][table="width: 500, class: grid"]
    Attached Files Attached Files
    Last edited by muddit0; 03-21-2018 at 11:19 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    01-10-2012
    Location
    Texas
    MS-Off Ver
    Excel 2010
    Posts
    651

    Re: There are 8 cities in the country of Eight, A, B, C, D, E, F, G and H.

    is this a homework assignment?
    Hope I could help - if your post has been solved don't forget to mark it as such.

    Clicking the * below is a great way to say thanks!

    "Drowning in 10 feet of water isn?t any different than drowning in a million feet. And if you can swim, it doesn?t matter how deep the ocean is. At some level, once you realize you?re in water that?s too deep to stand, you have to have a very different approach," - Joi Ito

  3. #3
    Registered User
    Join Date
    03-20-2018
    Location
    INDIA
    MS-Off Ver
    2016
    Posts
    11

    Re: There are 8 cities in the country of Eight, A, B, C, D, E, F, G and H.

    No its not homework

  4. #4
    Registered User
    Join Date
    03-20-2018
    Location
    INDIA
    MS-Off Ver
    2016
    Posts
    11

    Re: There are 8 cities in the country of Eight, A, B, C, D, E, F, G and H.


  5. #5
    Valued Forum Contributor
    Join Date
    01-10-2012
    Location
    Texas
    MS-Off Ver
    Excel 2010
    Posts
    651

    Re: There are 8 cities in the country of Eight, A, B, C, D, E, F, G and H.

    do you have flexibility in the layout / arrangement of the data? this is not really a very convenient format.

    attached is probably how i would tackle this problem... create a cumulative distance column and then a midpoint column and match on a greater than basis.
    Attached Files Attached Files
    Last edited by simarui; 03-20-2018 at 03:18 PM.

  6. #6
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,612

    Re: There are 8 cities in the country of Eight, A, B, C, D, E, F, G and H.

    title updated....
    Last edited by protonLeah; 03-20-2018 at 06:24 PM.
    Ben Van Johnson

  7. #7
    Registered User
    Join Date
    03-20-2018
    Location
    INDIA
    MS-Off Ver
    2016
    Posts
    11

    Re: There are 8 cities in the country of Eight, A, B, C, D, E, F, G and H.

    Thank you for your reply, But I want to do it without making any new data columns.

  8. #8
    Registered User
    Join Date
    12-21-2015
    Location
    United States
    MS-Off Ver
    2016
    Posts
    62

    Re: How to Use array match function in a distance matrix

    You could try this, though it is not tested.

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Would be easier if you could attach a workbook.

  9. #9
    Registered User
    Join Date
    03-20-2018
    Location
    INDIA
    MS-Off Ver
    2016
    Posts
    11

    Re: How to Use array match function in a distance matrix

    Workbook is attached now, thanks.

  10. #10
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2016
    Posts
    5,910

    Re: How to Use array match function in a distance matrix

    Change table1 to:

    A B C D E F G H
    0 200 350 500 250 850 1250 150

    Use array formula:

    =INDEX($C$11:$J$11,MATCH(D30,SUBTOTAL(9,OFFSET($C$12,,,1,COLUMN(C11:J11)-COLUMN(B11))),1))

    Enter with Ctrl+Shift+Enter.
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    03-20-2018
    Location
    INDIA
    MS-Off Ver
    2016
    Posts
    11

    Re: How to Use array match function in a distance matrix

    I want to do it without adding other column or changing the data structure

  12. #12
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2016
    Posts
    5,910

    Re: How to Use array match function in a distance matrix

    Array formula:

    =INDEX($C$11:$J$11,MATCH(D30,0.5*SUBTOTAL(9,OFFSET($C$12,,,COLUMN(C11:J11)-COLUMN(B11),
    COLUMN(C11:J11)-COLUMN(B11))),1))

  13. #13
    Registered User
    Join Date
    03-20-2018
    Location
    INDIA
    MS-Off Ver
    2016
    Posts
    11

    Re: How to Use array match function in a distance matrix

    Its working by using this formula but i am not able to understand it completly
    =index($c$11:$j$11,match(d30,0.5*subtotal(9,offset($c$11,,,column(c11:j11)-column(b11),column(c11:j11)-column(b11))),1))

    Thank you very much for helping

  14. #14
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Re: How to Use array match function in a distance matrix

    Cross-posted : https://www.mrexcel.com/forum/excel-...x-problem.html

    Your post does not comply with Rule 8 of our Forum RULES. Do not crosspost your question on multiple forums without including links here to the other threads on other forums.

    Cross-posting is when you post the same question in other forums on the web. The last thing you want to do is waste people's time working on an issue you have already resolved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser) to the cross-post.

    Expect cross-posted questions without a link to be closed and a message will be posted by the moderator explaining why. We are here to help so help us to help you!

    Read this to understand why we ask you to do this, and then please edit your first post to include links to any and all cross-posts in any other forums (not just this site).

  15. #15
    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,053

    Re: How to Use array match function in a distance matrix

    Doesn't the answer at Post 12 give the nearest city that Mr Z has ALREADY been to... not the nearest one, ahead or behind him??
    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

  16. #16
    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,053

    Re: How to Use array match function in a distance matrix

    This array formula gives the closest city (in front or behind):

    =INDEX($C$11:$J$11,MATCH(MIN(ABS(0.5*SUBTOTAL(9,OFFSET($C$12,,,COLUMN(C12:J12)-COLUMN(B12),COLUMN(C12:J12)-COLUMN(B12)))-D30)),ABS(0.5*SUBTOTAL(9,OFFSET($C$12,,,COLUMN(C12:J12)-COLUMN(B12),COLUMN(C12:J12)-COLUMN(B12)))-D30),0))

  17. #17
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: How to Use array match function in a distance matrix

    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  18. #18
    Registered User
    Join Date
    03-20-2018
    Location
    INDIA
    MS-Off Ver
    2016
    Posts
    11

    Re: How to Use array match function in a distance matrix

    Thank you very much for providing the solution.

  19. #19
    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,053

    Re: How to Use array match function in a distance matrix

    Who are you talking to????

  20. #20
    Registered User
    Join Date
    03-20-2018
    Location
    INDIA
    MS-Off Ver
    2016
    Posts
    11

    Re: How to Use array match function in a distance matrix

    Quote Originally Posted by Glenn Kennedy View Post
    This array formula gives the closest city (in front or behind):

    =INDEX($C$11:$J$11,MATCH(MIN(ABS(0.5*SUBTOTAL(9,OFFSET($C$12,,,COLUMN(C12:J12)-COLUMN(B12),COLUMN(C12:J12)-COLUMN(B12)))-D30)),ABS(0.5*SUBTOTAL(9,OFFSET($C$12,,,COLUMN(C12:J12)-COLUMN(B12),COLUMN(C12:J12)-COLUMN(B12)))-D30),0))
    Thank you very much Mr. Glenn Kennedy, It works.

  21. #21
    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,053

    Re: How to Use array match function in a distance matrix

    Make sure that you thank Phuocam, too. He did the hard part!!!

  22. #22
    Registered User
    Join Date
    03-20-2018
    Location
    INDIA
    MS-Off Ver
    2016
    Posts
    11

    Re: How to Use array match function in a distance matrix

    Quote Originally Posted by Phuocam View Post
    Array formula:

    =INDEX($C$11:$J$11,MATCH(D30,0.5*SUBTOTAL(9,OFFSET($C$12,,,COLUMN(C11:J11)-COLUMN(B11),
    COLUMN(C11:J11)-COLUMN(B11))),1))
    Thank you very much for providing the solution.

  23. #23
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: How to Use array match function in a distance matrix

    Another ARRAY FORMULA* in E30:
    Please Login or Register  to view this content.
    *Always press CTRL+SHIFT+ENTER to confirm entry after pasting or editing an ARRAY FORMULA in the Formula Bar.
    When copying the formula to other cells, make sure the copied cell is not part of the Paste Area.
    Last edited by leelnich; 03-21-2018 at 12:09 PM.
    Clicking the Add Reputation star below helpful posts is a great way to show your appreciation.
    Please mark your threads as SOLVED upon conclusion (Thread Tools above Post # 1). - Lee

+ 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] fix the cities in addresses
    By KingTamo in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-03-2018, 02:47 PM
  2. counting cities
    By TheVolkinator in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-26-2014, 02:35 PM
  3. Filterin of Cities in addresses
    By btiongsonjr in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 11-13-2013, 10:04 PM
  4. Replies: 0
    Last Post: 04-11-2013, 02:09 PM
  5. Many Cities into few Regions
    By Johnny Image in forum Excel General
    Replies: 2
    Last Post: 04-17-2012, 07:25 PM
  6. Add ‘country name’ column to worksheet from a list of country codes.
    By Ben Morton in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-02-2009, 09:24 AM
  7. Replies: 1
    Last Post: 06-30-2005, 02:05 AM

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