Closed Thread
Results 1 to 14 of 14

Distance between UK postcodes

  1. #1
    Registered User
    Join Date
    02-19-2011
    Location
    Cheshire
    MS-Off Ver
    365
    Posts
    1

    Distance between UK postcodes

    Hello,

    I have two cells in Excel (A1, B1) with a UK postcode in each.

    Are there any suggestions of how I can calculate the difference in Miles between the two postcodes with the resultant appearing in Cell C1?

    Presumably this will require VBA to solve.

    Your help would be appreciated

    Regards

    Pete

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    21,528

    Re: Distance between UK postcodes

    Code wise... store the below in a standard module in VBE:

    Please Login or Register  to view this content.
    You can then get the mileage using a formula along the lines of:

    Please Login or Register  to view this content.
    where A1 holds start post code and B1 destination post code

    If you want the estimated Travel Time

    Please Login or Register  to view this content.
    edit: for ref. above all taken/adapted from: http://www.excelforum.com/excel-gene...ing-times.html
    Last edited by DonkeyOte; 02-21-2011 at 09:41 AM. Reason: missing declaration (as notified by dcaraher below)

  3. #3
    Registered User
    Join Date
    12-04-2008
    Location
    Birmingham, UK
    MS-Off Ver
    Office 2007
    Posts
    43

    Re: Distance between UK postcodes

    I was having problems getting this to work, the debugger message was that the variable bUnit had not been defined.

    I defined this as a variant and it now works. Being a complete novice in VBA I'm not sure whether this is correct?

  4. #4
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    21,528

    Re: Distance between UK postcodes

    Thanks, bUnit should ideally be declared as a Byte (but Variant is fine).
    I will modify my prior post accordingly.

  5. #5
    Registered User
    Join Date
    04-13-2011
    Location
    Cambridgeshire
    MS-Off Ver
    Excel 2003
    Posts
    1

    Re: Distance between UK postcodes

    This was working great for me last week, but now only returns 0 miles.

    Any ideas?

  6. #6
    Registered User
    Join Date
    04-13-2011
    Location
    no
    MS-Off Ver
    no
    Posts
    2

    Re: Distance between UK postcodes

    Hi, I'm just starting to learn Excel and VBA, but after many hours and the help from information in this fourm I manage to make a worksheet to speed up the the filling of post code data and calculation of distances, using the code above. Thank you all guys that help in this forum!.
    Now to the point, My worksheet was also working last week but not now, retuning 0 instead of distance, I wonder if it is because a change on google maps code or because excel blocked acces to internet? how can i check this?

  7. #7
    Registered User
    Join Date
    04-18-2011
    Location
    Letchworth
    MS-Off Ver
    Excel 2010
    Posts
    20

    Re: Distance between UK postcodes

    Quote Originally Posted by Elpropio View Post
    Hi, I'm just starting to learn Excel and VBA, but after many hours and the help from information in this fourm I manage to make a worksheet to speed up the the filling of post code data and calculation of distances, using the code above. Thank you all guys that help in this forum!.
    Now to the point, My worksheet was also working last week but not now, retuning 0 instead of distance, I wonder if it is because a change on google maps code or because excel blocked acces to internet? how can i check this?
    Love this bit of code and have been using it almost daily since i discovered it a few weeks back. However I too have found it not working when I've tried it today. Has anyone managed to overcome these issues?

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

    Re: Distance between UK postcodes

    Have you guys looked at the link that DonkeyOte posted in the first reply?

    The problem came up there too and it shows how it was overcome. You can adapt to your current code.
    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.

  9. #9
    Registered User
    Join Date
    12-15-2011
    Location
    Tiverton, Devon
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Distance between UK postcodes

    Hi

    I've created a spreadsheet with a series of postcodes down one side which I want to be able to calculate the distances between them. However, when I use the function it always comes back with a 0. After checking using a few well placed msgbox's, I've found it's coming back with NOT FOUND. However, I place the URL into Explorer the route appears fine.

    Any ideas?

    Sorry, how do you delete?
    Last edited by Woozer74; 12-15-2011 at 04:59 PM. Reason: Wrong Forum

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

    Re: Distance between UK postcodes

    Welcome to the Forum, unfortunately:

    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread.

  11. #11
    Registered User
    Join Date
    09-17-2011
    Location
    South Wales UK
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Distance between UK postcodes

    Hello clever ones

    I am based in the UK and wanted to see it the code used here will work in the UK also. I have tried ammending the code so that URL shows

    http://maps.google.com/maps?f=d&source=s_d

    or for what I assume in the UK would be

    http://maps.google.co.uk/maps?f=d&source=s_d (This one in IE loads the UK map)

    I have try all the suggestions in the thread but I cannot get the code to work. I have tried Authors code with his suggestions and the function returns 0

    Any help would be appreciated. THank you

    WelshPunk

    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    09-17-2011
    Location
    South Wales UK
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Distance between UK postcodes

    I guess no then lol!

  13. #13
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    22,731

    Re: Distance between UK postcodes

    I have a file that gives you the distance between UK postcodes (contained in a lookup table, so no access to the internet is needed). Do you want me to post a copy here?

    Pete

  14. #14
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    21,528

    Re: Distance between UK postcodes

    @WelshPunk,

    Unfortunately:

    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread.

Closed 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