+ Reply to Thread
Results 1 to 10 of 10

Using VBA to pull driving distance between two zio codes

  1. #1
    Forum Contributor
    Join Date
    06-11-2018
    Location
    Lebanon, NH
    MS-Off Ver
    2000 and 2010
    Posts
    106

    Using VBA to pull driving distance between two zio codes

    Good morning!
    I have a worksheet containing 3122 Zip codes. Those are the only zip codes I need to worry about. The beginning zip code will always be our plant. I'd like to be able to plug in a formula in another workbook to retrieve the driving distance between our plant and any of the destination zip codes in that sheet. Currently I'm trying to populate the worksheet with the driving mileage between the plant and the list of zip codes. I found this macro on the web and made a couple of changes. When I run the macro it just spins it's wheels. I've never tried to call a web page for data with VBA. I fear that I am over my head on this one.
    Any input, assistance or suggestions are very much appreciated.
    thanks much!
    Bill
    Please Login or Register  to view this content.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2506 Win 11
    Posts
    24,767

    Re: Using VBA to pull driving distance between two zio codes

    https://analystcave.com/excel-calcul...een-addresses/
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Contributor
    Join Date
    06-11-2018
    Location
    Lebanon, NH
    MS-Off Ver
    2000 and 2010
    Posts
    106

    Re: Using VBA to pull driving distance between two zio codes

    Alansidman,
    Thanks much for the link. I looked into that page and unfortunately they require either an address or coordinates. The only absolute that I am going to have going forward is zip code. I do not want to get a personal API Key and associate it with a work project. I will continue to look for a solution using zip codes.
    Thanks much
    Bill

  4. #4
    Forum Contributor
    Join Date
    10-01-2018
    Location
    Virginia Beach, VA
    MS-Off Ver
    365
    Posts
    129

    Re: Using VBA to pull driving distance between two zio codes

    Kind of a stone age solution, but you could always have an admin, temp, or intern look up each zip code manually and populate a spreadsheet with the driving distance. Assuming an average of 30 seconds per zip code, it would take about three 8 hour workdays to complete.

    Or, perhaps write code in your worksheet that checks your list of zip codes for the driving distance, and if it hasn't already been entered then a message box directs the user to the website to look it up manually and enter the driving distance, which would then get written to the sheet with the zip codes. That way, you build your database on an as-needed basis, and only need to look up a zip code if it hasn't been used previously.


    Might not be elegant, just trying to think outside the box.

  5. #5
    Forum Contributor
    Join Date
    06-11-2018
    Location
    Lebanon, NH
    MS-Off Ver
    2000 and 2010
    Posts
    106

    Re: Using VBA to pull driving distance between two zio codes

    Thanks Arnold,
    I appreciate your response. Unfortunately that is not an option. I'm tasked with delivering a complete solution. I found a download at https://sourceforge.net/projects/zips/ with all zip codes that includes Town,Stare, ZIP and Lat/Lon. I'll try to make something out of that.
    Thanks you
    Bill

  6. #6
    Forum Contributor
    Join Date
    10-01-2018
    Location
    Virginia Beach, VA
    MS-Off Ver
    365
    Posts
    129

    Re: Using VBA to pull driving distance between two zio codes

    Gotcha. I find the project intriguing, I hope you'll update the thread with your solution once you find one... I like the idea of pinging a website for data from within excel. Seems like something that could be useful for many applications. Best of luck!

  7. #7
    Forum Contributor
    Join Date
    06-11-2018
    Location
    Lebanon, NH
    MS-Off Ver
    2000 and 2010
    Posts
    106

    Re: Using VBA to pull driving distance between two zio codes

    Good afternoon!!
    After fiddling around for a while I located a .csv list of zip codes for all 50 states from a web site complete with latitude and longitude. I filtered the list to get the 6 states I wanted, then plugged that data into the Haversine formula after substituting the cell addresses where my Lat/Long data was located into the formula. I now have a worksheet with 6 states with all zip codes, longitude and latitude for each municipality and a column with the miles from our facility. This data should be relatively easy to mine using VBA.
    I can now go back to my project and do a vlookup to the sheet where the zipcodes and lat/lon is stored and mmileage from our facility will automatically populate where needed
    Thanks again to the folks who offered solutions. I appreciate it. Although I didn't use your suggestions they triggered me to go in a different direction and therefore solved my issue.
    The folks on this forum are a treasure for sure.
    Thanks,
    Bill
    Last edited by billfinnjr; 03-13-2019 at 01:40 PM.

  8. #8
    Forum Contributor
    Join Date
    10-01-2018
    Location
    Virginia Beach, VA
    MS-Off Ver
    365
    Posts
    129

    Re: Using VBA to pull driving distance between two zio codes

    Keep in mind, if you're calculating the miles between two points using longitude and latitude, you're getting straight line, "as the crow flies" distances, and not actual driving distances. The farther away from your shop the destination is, the less accurate your distance is likely to be. You might want to compare your results on a couple test zips against a service like Google Maps or MapQuest, to see if the difference is more than negligible... it may be a non-issue, but it's worth checking.

  9. #9
    Forum Contributor
    Join Date
    06-11-2018
    Location
    Lebanon, NH
    MS-Off Ver
    2000 and 2010
    Posts
    106

    Re: Using VBA to pull driving distance between two zio codes

    Arnold,
    Thanks for the thought. I am actually in the process of sampling the data and checking to see what percentage of the distances are off. The furthest distance will be 300 miles. I may end up putting a percentage adder in the formula if my results show a need. This doesn't need to be .001 accurate, just within 5-10 miles

    Thanks!
    Bill

  10. #10
    Forum Contributor
    Join Date
    10-01-2018
    Location
    Virginia Beach, VA
    MS-Off Ver
    365
    Posts
    129

    Re: Using VBA to pull driving distance between two zio codes

    If you're only dealing with a range of 300 miles, I doubt it will be a big enough issue to worry about. My company is located on the east coast, and ships product all over the country, and sometimes beyond the borders... so highway routing would play into my calculations far more significantly, as some routes require travel through states that wouldn't even be touched by a point-to-point line. I was thinking on my terms, not yours, LOL! Glad you got it worked out!

+ 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. Driving distance using google API
    By AV114 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-11-2018, 07:51 AM
  2. Use Google Maps to return driving time and distance
    By KevanC in forum Excel General
    Replies: 2
    Last Post: 12-22-2013, 11:16 PM
  3. Help With VBA code for getting driving distance.
    By anfdrew in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-22-2013, 11:06 PM
  4. Query Google maps to return driving distance and time
    By mickisme in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-27-2012, 06:18 AM
  5. Use mapquest or google maps to get driving distance?
    By DonkeyOte in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-19-2010, 10:04 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