+ Reply to Thread
Results 1 to 6 of 6

Thread: find the minimum distance between two points using two separate lists?

  1. #1
    Registered User
    Join Date
    07-05-2011
    Location
    USA
    MS-Off Ver
    Excel 2011
    Posts
    3

    Exclamation find the minimum distance between two points using two separate lists?

    Is it possible to find the minimum distance between two points using two separate lists of different lengths without creating separate columns of equal row sizes

    ? I am trying to find the shortest distance form one point to another which is a fixed value. I am using the standard distance formula: =SQRT(((X2-X1)^2)+((Y2-Y1)^2)+((Z2-Z1)^2)).

    My X1,Y1, Z1, has 2,000 rows in three columns that need to be compared to find the minimum distance from my one row/column of X2,Y2,Z2.

    Is there a command that could go through and use each row of the X1, Y1, Z1, while looking for the MIN of the above formula without having to create an equal amount of rows for the X2, Y2, Z2?

    I know I could do it by running this out the long way and then finding the min after I do all the math but I am wondering if there is an automated way for Excel to go through and do the forumla and then only return the MIN value?

    Thank you in advance!

    Dave
    Last edited by drozle; 07-06-2011 at 11:13 PM. Reason: I broke a rule by accident.

  2. #2
    Valued Forum Contributor MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    5,285

    Re: Complex Formula automation?

    Hi Dave and welcome to the forum,

    See if the attached isn't what you want. It calculates the distance to the other points, pulls out the min distance and tells what Other Point it is.
    Attached Files Attached Files
    One test is worth a thousand opinions.
    Click the * below to say thanks.

  3. #3
    Registered User
    Join Date
    07-05-2011
    Location
    USA
    MS-Off Ver
    Excel 2011
    Posts
    3

    Question Re: Complex Formula automation?

    Actually, the issue is not the formula itself but the method in what I want to do and how to do it (thank you though Marv ).

    Attached is the spread sheet in question . Columns B, C, and D is my aircraft trajectory while columns G, H, and I are the points of interest. I need to calculate the MIN value per each gate (Column F is the gate number). What I would like is to find a way for excel to run the distance formula (which I have as: =SQRT(((X2-X1)^2)+((Y2-Y1)^2)+((Z2-Z1)^2))). The issue I have is that I do want to have to make 1,936 rows of the same gate value just to then find the min value.

    Is there a way to add a FUNCTION command that would have excel go through Columns B, C, and D, comparing them to each gate listed in G, H, and I and then only export the MIN value per each individual gate?

    It would not be a big deal if I only had to do this once but I have to do this about 300 times for a test I am doing so I want to be able to only copy paste the flight trajectory data.

    Thanks in advance

    David
    Attached Files Attached Files

  4. #4
    Valued Forum Contributor MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    5,285

    Re: Complex Formula automation?

    OK David - hold on to your hat - here is the answer(s). (I think )

    Find the attached.
    1. I made cell E2 the Gate number and the rest of column E is the distance between those coordinates.
    2. Look at the formula in E3 and down as:
    =SQRT(((B3-VLOOKUP($E$2,$G$3:$J$36,2,FALSE))^2)+((C3-VLOOKUP($E$2,$G$3:$J$36,3,FALSE))^2)+((D3-VLOOKUP($E$2,$G$3:$J$36,4,FALSE))^2))
    Which is long winded to go lookup the X,Y,Z gate coordinates based on their number in col G
    3. You put in the Gate Number in E3 and all the distances are calculated for that gate.
    4. A little VBA Loop supplies the rest. It goes down the gate numbers - putting them in cell E2 and then brings back the Minimum value of all those distances into col K across from the gate number.

    Code looks like:
    Sub MinOfGates()
    Dim LastGateRow As Double
    Dim GateCtr As Double
    Dim LastSpeedRow As Double
    
    LastGateRow = Cells(Rows.Count, "G").End(xlUp).Row
    LastSpeedRow = Cells(Rows.Count, "A").End(xlUp).Row
    
        For GateCtr = 3 To LastGateRow
            Range("E2") = Cells(GateCtr, "G")
            Application.Calculate
            Cells(GateCtr, "K") = WorksheetFunction.Min(Range(Cells(3, "E"), Cells(LastSpeedRow, "E")))
        Next GateCtr
    
    End Sub
    This is a GREAT example of letting Excel and VBA work together in an efficient way.

    See attached. Hope it all helps.
    Attached Files Attached Files
    One test is worth a thousand opinions.
    Click the * below to say thanks.

  5. #5
    Registered User
    Join Date
    07-05-2011
    Location
    USA
    MS-Off Ver
    Excel 2011
    Posts
    3

    Thumbs up Re: Complex Formula automation?

    Holly Moly Marv!

    That is AMAZING!

    So if I may ask, a few questions:

    1. If I copy and paste new trajectories into the spreadsheet you provided, will it update accordingly?

    2. Is there a way to do this without VBA? The reason I ask is I have 0 coding experience.

    Many MANY thanks again Marv!

  6. #6
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,637

    Re: Complex Formula automation?

    Your post does not comply with Rule 1 of our Forum RULES. Your post title should accurately and concisely describe your problem, not your anticipated solution. Use terms appropriate to a Google search. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will be addressed according to the OP's experience in the forum: If you have less than 10 posts, expect (and respond to) a request to change your thread title. If you have 10 or more posts, expect your post to be locked, so you can start a new thread with an appropriate title.
    To change a Title on your post, click EDIT then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.

    PLEASE PM WHEN YOU HAVE DONE THIS AND I WILL DELETE THIS POST
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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.2.0