+ Reply to Thread
Results 1 to 5 of 5

calculating shortest distance between two points

  1. #1
    Registered User
    Join Date
    08-07-2019
    Location
    canada
    MS-Off Ver
    excel
    Posts
    2

    calculating shortest distance between two points

    I have a set of 9 nodes, with the distance between each pair of connected nodes. For example:

    Node distance
    (1,2) 72
    (1,3) 31
    (3,4) 81

    I need a macro that will calculate the shortest distance between node 1 and each of the other nodes (2,3 and 4), and than will create a table that will sort the result by ascending distance.

    The result I am expecting would be

    (1,3) 31
    (1,2) 72
    (1,4) 112

    I am new to macros. Anyone can help ?

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,930

    Re: calculating shortest distance between two points

    Does it have to be a VBA macro? Here's an implementation of the shortest path problem that uses worksheet functions and the built in Solver: https://www.excel-easy.com/examples/...h-problem.html
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  3. #3
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: calculating shortest distance between two points

    Hi captain and welcome to the forum,

    Are your "nodes" really cartesian points like (x,y) points on a plane? When you write node (1,2) is that point (1,2) or 2 different nodes where we don't know where they are?

    I think I can solve your problem but need an example workbook with a few answers.

    Welcome to the forum

    Please attach a sample workbook (not a picture or pasted copy). Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Registered User
    Join Date
    08-07-2019
    Location
    canada
    MS-Off Ver
    excel
    Posts
    2

    Re: calculating shortest distance between two points

    They are 2 different nodes. Attached is a sample worksheet
    Attached Files Attached Files

  5. #5
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,778

    Re: calculating shortest distance between two points

    If a formula based solution is acceptable then try the following as modeled on the 'Before' sheet:
    1. Populate G2:G7 using: =IFERROR(AGGREGATE(15,6,C$2:C$6,ROWS(A$1:A1)),"")
    2. Populate E2:F7 using: =IF($G2="","",INDEX(A$2:A$6,AGGREGATE(15,6,(ROW(A$2:A$6)-ROW(A$1))/($C$2:$C$6=$G2),COUNTIFS($G$2:$G2,$G2))))
    Let us know if you have any questions.
    Attached Files Attached Files
    Consider taking the time to add to the reputation of everybody that has taken the time to respond to your query.

+ 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. Calculating distance between two latitude longitude points
    By visha_1984 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-16-2018, 02:04 AM
  2. Excel Calculating Distance between two points.
    By Matty5894 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-18-2014, 12:43 PM
  3. Calculating Angle and Distance from 3D points (x,y,z)
    By frowny in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 08-09-2014, 10:33 PM
  4. [SOLVED] Calculating distance between many GPS points and sorting by distance
    By jackalek in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 07-14-2014, 08:27 AM
  5. shortest distance between a point and a line
    By stockgoblin42 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-04-2013, 02:18 PM
  6. [SOLVED] Calculating Distance between 2 points.
    By isdouble in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-20-2012, 07:17 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