+ Reply to Thread
Results 1 to 9 of 9

Shortest Path Between Cells (VBA)

  1. #1
    Registered User
    Join Date
    03-02-2014
    Location
    Haarlem, Netherlands
    MS-Off Ver
    Excel 2013
    Posts
    3

    Shortest Path Between Cells (VBA)

    Dear all,

    I am new to this forum so excuse me if this question is already solved..

    So, here's my problem..
    I am working on a project to clear festival events with simulation.

    Therefore I need a grid of Excel cells (the field), let's say 11x11 (B2:L12).
    And the exit is in cell A7.

    I am looking for an algorithm which fills this field with distances to the exit.
    For horizontal and vertical movements the distance is 1,
    and for diagonal movements the distance is 1.5

    Say I made a class Coordinate which has two points, X & Y
    I declare a variable point, as the location I am in (the active cell) and a constant exit (the coordinate of the exit)

    And then I would like a function in VBA which does:

    Please Login or Register  to view this content.

    Does anyone has an idea how to approach this??

    Many thanks!

    Greetings,

    Bas

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Shortest Path Between Cells (VBA)

    attach please a sample file and explain better how you want use it
    If solved remember to mark Thread as solved

  3. #3
    Registered User
    Join Date
    03-02-2014
    Location
    Haarlem, Netherlands
    MS-Off Ver
    Excel 2013
    Posts
    3

    Re: Shortest Path Between Cells (VBA)

    Sorry that I am not clear..

    Shortest distance algorithms usually use the distances between A to B, A to C etc. and take the minimum.
    In my case, these distances are not given, but they are cells.

    Here is my file:

    Grid Shortest Distance.xls


    Gr. Bas

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,441

    Re: Shortest Path Between Cells (VBA)

    This will handle an empty room with varying exit. 999 denotes the exit.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Cheers
    Andy
    www.andypope.info

  5. #5
    Registered User
    Join Date
    03-02-2014
    Location
    Haarlem, Netherlands
    MS-Off Ver
    Excel 2013
    Posts
    3

    Re: Shortest Path Between Cells (VBA)

    Yes! That's it! Thanks Andy!

    Just out of curiousity, is it possible to implement bars (obstacles) in the field with this method?
    I actually dropped this idea because I didn't know how to do this, but do you have an idea?

    Many thanks!

    Bas

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,441

    Re: Shortest Path Between Cells (VBA)

    Obstacles will make this a much more complex problem, certainly beyond a forum post solution.

    Major things to consider would be how far ahead you should check and whether multple blocks should be anticipated.

  7. #7
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,441

    Re: Shortest Path Between Cells (VBA)

    Okay I could not leave it alone.

    This variation will handle interior walls and multiple exits. I have added conditional formatting so exit, walls and unassigned distances will appear coloured.
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    12-14-2017
    Location
    INDIA
    MS-Off Ver
    2017
    Posts
    5

    Re: Shortest Path Between Cells (VBA)

    i have node list and find all available paths between any 2 nodes. as attached in excel or excel vba.1.jpg2.jpg
    Last edited by sks4444; 07-18-2018 at 01:06 PM.

  9. #9
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,946

    Re: Shortest Path Between Cells (VBA)

    sks4444 welcome to the forum

    Unfortunately your post does not comply with Rule 2 of our Forum RULES. Do not post a question in the thread of another member -- start your own thread.

    If you feel an existing thread is particularly relevant to your need, provide a link to the other thread in your new thread.

    Old threads are often only monitored by the original participants. New threads not only open you up to all possible participants again, they typically get faster response, too.
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

+ 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. 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
  2. [SOLVED] Multiple Table lookup-shortest approach
    By vlady in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 03-12-2013, 09:17 PM
  3. Excel 2007 : Conditional formatting for shortest time
    By darkknight4251 in forum Excel General
    Replies: 10
    Last Post: 12-22-2011, 11:01 AM
  4. Create Unique List in Shortest Time
    By modytrane in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-17-2009, 03:54 PM
  5. shortest between 2 numbers
    By Martindelica in forum Excel General
    Replies: 4
    Last Post: 11-16-2007, 09:32 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