+ Reply to Thread
Results 1 to 3 of 3

Distance Function Not Returning Correct Figure

  1. #1
    Registered User
    Join Date
    08-22-2020
    Location
    U.S.
    MS-Off Ver
    Excel 2007
    Posts
    13

    Distance Function Not Returning Correct Figure

    I am having issues getting my Macro to return the full number when combined with a Google Distance Matrix.

    For Example:

    10887 Clyde St., Howell, WA

    28047 Fir Avenue, Novi, MI

    This should return a mileage of over 1000 but my Macro only returns a 1. This happens with any number over 999.

    I have attached my Macro.

    The function is =getdistance(originaddress,destinationaddress)

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    [/CODE]

    I am pretty sure the problem lies in the Set regex = CreateObject("VBScript.RegExp"): regex.Pattern = ""text"".*?([0-9]+)":
    Last edited by Megatron01; 11-06-2020 at 03:48 AM.

  2. #2
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,462

    Re: Distance Function Not Returning Correct Figure

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (Note: this change is not optional. No help to be offered until this moderation request has been fulfilled.)

  3. #3
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,907

    Re: Distance Function Not Returning Correct Figure

    After more than half a day, and even though I know very little about using RegExp for this sort of thing, I will note that, when I tried your function, Google returned a "API key is invalid" message -- because I don't have a Google API. I don't know how many of us have Google API keys that we can use, but, as it stands, only those with a Google API key would really be able to help you debug this. I get the impression that you are not having trouble getting a return value from Google, but that your problem is about extracting a number from that text string. I think it would help us help you if you would share typical result strings that Google returns -- what is the value in objHttp.responsetext. Then we may be able to help you without needing to query Google ourselves.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

+ 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. [SOLVED] SUM function not returning correct result
    By rayted in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 02-26-2018, 11:04 AM
  2. [SOLVED] Averageifs function not returning correct average
    By CSherman in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-02-2017, 11:11 PM
  3. Percentile Function is not returning correct results
    By walters in forum Excel General
    Replies: 1
    Last Post: 03-10-2015, 10:52 AM
  4. Please Help!! Simple VLOOKUP Function is returning #N/A and I can't figure it out!
    By brittany.bardo in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 01-09-2015, 06:49 PM
  5. [SOLVED] IF Comparison Function Not Returning Correct Data
    By emlit in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 01-24-2014, 01:44 PM
  6. Indirect function not returning correct value
    By iamskippy in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 09-16-2013, 04:28 PM
  7. [SOLVED] MAX Function not returning correct value
    By Phil in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-28-2006, 05:20 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