+ Reply to Thread
Results 1 to 12 of 12

How I calculate distance 2 colum with VBA code (Radius of the earth in Kilometer)

  1. #1
    Registered User
    Join Date
    04-23-2013
    Location
    Thailand
    MS-Off Ver
    Excel 2007
    Posts
    28

    Smile How I calculate distance 2 colum with VBA code (Radius of the earth in Kilometer)

    Dear Sir
    How I calculate distance 2 colum with VBA code (Radius of the earth in Kilometer)
    Step
    ----------------------------
    If
    1.Select Location ID at Worksheet("INPUT").Cell ("2:2")
    2.Select Radius less than equal at Worksheet("INPUT").Cell ("2:3")
    3.Get Result at Worksheet("INPUT").Range ("F2:G")
    If
    1.If Select New Location ID at Worksheet("INPUT").Cell ("2:2")
    2.Select Radius less than equal at Worksheet("INPUT").Cell ("2:3")Location-distance-.png
    3.Get Result at Worksheet("INPUT").Range ("F2:G")

    Thank you
    arttyv1

    ----------------------------------------------------
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by lotto009; 01-23-2020 at 07:33 AM.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: How I calculate distance 2 colum with VBA code (Radius of the earth in Kilometer)

    Are you trying to calculate the great circle distance between any two lat/long points?

    If not would you explain exactly what you are trying to do, manually add some results and importantly explain your calculation for arriving at the results.
    I'm struggling to understand why you need a radius drop down box since the earth's radius is a constant (for all practical purposes - I know it varies from pole to equator).

    Neither do I understand what the Source and Target columns are.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,302

    Re: How I calculate distance 2 colum with VBA code (Radius of the earth in Kilometer)

    I do not understand your set-up and glad I am not using this as my primary navigation aid.
    However I do understand the link attached.


  4. #4
    Registered User
    Join Date
    04-23-2013
    Location
    Thailand
    MS-Off Ver
    Excel 2007
    Posts
    28

    Re: How I calculate distance 2 colum with VBA code (Radius of the earth in Kilometer)

    Thank you for feedback I am attempt to edit formula soon tonight and will feedback ASAP
    SO
    I need to
    1.Select Location ID at Worksheet("INPUT").Cell ("2:2")
    2.Select Radius less than equal at Worksheet("INPUT").Cell ("2:3")
    Because
    I would like to limit Radius(Km) no need to calculate all location in Worksheet("Data").range ("B2:C")

    3.Get Result at Worksheet("INPUT").Range ("F2:G")
    4.SOURCE& TARGET is mean
    -SOURCE=Start Point
    -TARGET =Stop Point (Destination)
    Kindly to check can do or not
    Regards
    art

  5. #5
    Registered User
    Join Date
    04-23-2013
    Location
    Thailand
    MS-Off Ver
    Excel 2007
    Posts
    28

    Re: How I calculate distance 2 colum with VBA code (Radius of the earth in Kilometer)

    Thank you after I check with there
    1.Must be convert LATITUDE&LONGITUDE(Decimal Degree) to format (Degrees,Minutes,Seconds)
    13.52339 100.65135 Latitude: 37° 57' 3.7203" S,Longitude: 144° 25' 29.5244" E

    2.In web there have 2 location So I have many Destinations
    3.I will attempt to is work or not
    Thank you
    art

  6. #6
    Registered User
    Join Date
    04-23-2013
    Location
    Thailand
    MS-Off Ver
    Excel 2007
    Posts
    28

    Re: How I calculate distance 2 colum with VBA code (Radius of the earth in Kilometer)

    Dear
    I used
    Formula Distance(Km)
    =ACOS(COS(RADIANS(90-Lat1)) *COS(RADIANS(90-Lat2)) +SIN(RADIANS(90-Lat1)) *SIN(RADIANS(90-Lat2)) *COS(RADIANS(Long1-Long2))) *6371

    Can edit my code because code not exactly as needed

    Thank you

  7. #7
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: How I calculate distance 2 colum with VBA code (Radius of the earth in Kilometer)

    Are you still looking for help.

    If so I don't understand what you are trying to do, and trying to reverse engineer your macro into a meaningful statement of requirement I find difficult to do.

    If you'd like to review what I said in post #2 and address the points I made then maybe we can help further.

    With all these things a sample list of inputs and the manually calculated results you expect are vital so that we can understand the overall goal. Be sure to explain your calculations that produce the results you show,

  8. #8
    Registered User
    Join Date
    04-23-2013
    Location
    Thailand
    MS-Off Ver
    Excel 2007
    Posts
    28

    Unhappy Re: How I calculate distance 2 colum with VBA code (Radius of the earth in Kilometer)

    Dear Richard
    After I revise decode vba my code is WORK is FINE with small row
    If large Row many data is not working
    Please revise my code is not work
    Thank you

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by lotto009; 01-28-2020 at 03:34 AM. Reason: not working

  9. #9
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: How I calculate distance 2 colum with VBA code (Radius of the earth in Kilometer)

    This will already speed things up significantly.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by bakerman2; 01-28-2020 at 07:38 AM.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  10. #10
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: How I calculate distance 2 colum with VBA code (Radius of the earth in Kilometer)

    @ lotto009

    Please notice that I've made some changes to my previous post to make the code a tiny bit faster and some errortrapping when a startlocation isn't found in Column A.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

    Also thanks for rep+.

  11. #11
    Registered User
    Join Date
    04-23-2013
    Location
    Thailand
    MS-Off Ver
    Excel 2007
    Posts
    28

    Re: How I calculate distance 2 colum with VBA code (Radius of the earth in Kilometer)

    Dear Bakeman2
    WOWWWWW your code very SUPER NICE!!!!
    Thank you for kindly investigate I am beginner
    Thank you krab
    art

  12. #12
    Registered User
    Join Date
    04-23-2013
    Location
    Thailand
    MS-Off Ver
    Excel 2007
    Posts
    28

    Red face Re: How I calculate distance 2 colum with VBA code (Radius of the earth in Kilometer)

    New I can do I edit
    by command
    HTML Code: 
    is Cleared
    Thank you
    Attached Files Attached Files
    Last edited by lotto009; 02-07-2020 at 10:39 AM. Reason: can sole by my self

+ 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. Trying to add tracks to waypoints in Google Earth VBA code
    By Kestrel Aviation in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-10-2019, 10:17 PM
  2. Replies: 30
    Last Post: 05-02-2019, 06:44 PM
  3. [SOLVED] VBA code to calculate the distance between point and the regression line
    By Lalikos in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-18-2016, 10:25 AM
  4. [SOLVED] Kilometer range with IF and or formula.
    By ricky84 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 08-20-2015, 07:55 AM
  5. Find locations within a radius of zip code and return location info for mail merge
    By eamador in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-23-2013, 12:29 AM
  6. Calculate distance
    By mukesh mishra in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-09-2013, 06:23 AM
  7. how to calculate facets lengths and radius
    By stephen1000 in forum Excel General
    Replies: 12
    Last Post: 12-02-2008, 05:55 PM

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.6.0 RC 1