+ Reply to Thread
Results 1 to 23 of 23

Need Distance Between Zip Codes

  1. #1
    Registered User
    Join Date
    06-05-2008
    Posts
    21

    Need Distance Between Zip Codes

    I have two columns, zipA and zipB. There are over 7000 rows and I need to calculate the distance between zipA and zipB for each row (so the result should be over 7000 rows of distances (in miles)). I posted this in the programming board because I figured it would require some. I don't have any add-ons.
    Last edited by drock; 02-27-2009 at 09:34 AM.
    iLove my iMac

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Need Distance Between Zip Codes

    Can you show a better example of the current layout and an example or 2 of expected results?

    Possibly attach a sample workbook?
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  3. #3
    Registered User
    Join Date
    06-05-2008
    Posts
    21

    Re: Need Distance Between Zip Codes

    Please see attached. There are in total about 7,500 rows. The column I need filled is C, "Distance_Between_(m)"
    Attached Files Attached Files

  4. #4
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Need Distance Between Zip Codes

    Where's the table of distances? Where's the raw data coming from?

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Need Distance Between Zip Codes

    How are the zip codes made up?
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  6. #6
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Need Distance Between Zip Codes

    Depends on the country and site you use for lookup if you are doing a web lookup.

    See my post at MrExcel for an example.

  7. #7
    Registered User
    Join Date
    06-05-2008
    Posts
    21

    Re: Need Distance Between Zip Codes

    I work for an auto auction company. The zip codes are from one dealer to another. I have dealer name, address, zip, state ,and a few other things. I just included the zips because I figured that is all that is prudent. Basically, I was given a list of zip codes and I need to find the distance between the two.

  8. #8
    Registered User
    Join Date
    06-05-2008
    Posts
    21

    Re: Need Distance Between Zip Codes

    Quote Originally Posted by Kenneth Hobson View Post
    Depends on the country and site you use for lookup if you are doing a web lookup.

    See my post at MrExcel for an example.
    They will all be US zips.

  9. #9
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Need Distance Between Zip Codes

    Macs don't support VBA, right?
    Entia non sunt multiplicanda sine necessitate

  10. #10
    Registered User
    Join Date
    06-05-2008
    Posts
    21

    Re: Need Distance Between Zip Codes

    My personal computers are macs, but I use Windows machines at work.

  11. #11
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Need Distance Between Zip Codes

    Driving distance or airline distance?

  12. #12
    Registered User
    Join Date
    06-05-2008
    Posts
    21

    Re: Need Distance Between Zip Codes

    Although driving distance would be ideal, I'm more than willing to accept bird-flight distance because I realize it would probably be easier.

  13. #13
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Need Distance Between Zip Codes

    You can get lat/lon of zip codes at http://www.census.gov/geo/www/gazett...es2k.html#zcta

    This function returns the central angle between two lat/lons:
    Please Login or Register  to view this content.
    For example,

    Please Login or Register  to view this content.
    The formula in H2 and down is =3960 * CentralAngle(B2, C2, E2, F2) for distances in statute miles.
    Last edited by shg; 02-26-2009 at 04:34 PM.

  14. #14
    Registered User
    Join Date
    06-05-2008
    Posts
    21

    Re: Need Distance Between Zip Codes

    Thank you. I'll give it a whirl and let you know!

  15. #15
    Registered User
    Join Date
    06-05-2008
    Posts
    21

    Re: Need Distance Between Zip Codes

    I am a VBA newb. I formatted my sheet exactly like your example above and copy/pasted the code you supplied into the Visual Basic Editor. When I try to recall the function in the worksheet the error says, "the formula contains unrecognized text."

  16. #16
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Need Distance Between Zip Codes

    Post the workbook.

  17. #17
    Registered User
    Join Date
    06-05-2008
    Posts
    21

    Re: Need Distance Between Zip Codes

    Well......I came into work this morning and it works now!!! Thank you so much!

  18. #18
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Need Distance Between Zip Codes

    To answer the question in your PM, 3960 is roughly the mean earth radius in statute miles.

  19. #19
    Registered User
    Join Date
    02-23-2011
    Location
    Grand Rapids, MI
    MS-Off Ver
    Office 2010
    Posts
    14

    Re: Need Distance Between Zip Codes

    Could you post the workbook of this working?
    Do you need to input all of the zips lat/long in? or was there an automated way to do this?
    Thanks!

  20. #20
    Registered User
    Join Date
    08-06-2012
    Location
    FSD
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Need Distance Between Zip Codes

    Quote Originally Posted by ninehigh View Post
    Could you post the workbook of this working?
    Do you need to input all of the zips lat/long in? or was there an automated way to do this?
    Thanks!
    I second that, a post of the spreadsheet would be very helpful. Thanks!

  21. #21
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Need Distance Between Zip Codes

    CStyle,

    Unfortunately you need to post your question in a new thread, it's against the forum rules to post a question in the thread of another user. If you create your own thread, any advice will be tailored to your situation so you should include a description of what you've done and are trying to do. Also, if you feel that this thread is particularly relevant to what you are trying to do, you can surely include a link to it in your new thread.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  22. #22
    Registered User
    Join Date
    08-06-2012
    Location
    FSD
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Need Distance Between Zip Codes

    Quote Originally Posted by arlu1201 View Post
    CStyle,

    Unfortunately you need to post your question in a new thread...
    Thanks, did not know that.

  23. #23
    Registered User
    Join Date
    11-12-2013
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Need Distance Between Zip Codes

    Post #13 by shg was very useful to me (almost 5 years later). Two things I found:

    1) ZIP code file is now at http://www.census.gov/geo/maps-data/...teer/zcta5.zip
    2) the longitudes for all 4 ZIPs in the example are radically different from actuals for those ZIPs, but the CentralAngle function works fine (tested with actual longitudes and verified using http://www.movable-type.co.uk/scripts/latlong.html)

    Thanks for such a helpful post.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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