+ Reply to Thread
Results 1 to 31 of 31

Query needed - user enters zip code and chooses radius and matches against another table

  1. #1
    Registered User
    Join Date
    04-15-2019
    Location
    Chicago, IL
    MS-Off Ver
    Office 365
    Posts
    51

    Query needed - user enters zip code and chooses radius and matches against another table

    Hi,

    Not sure if this is the right forum...

    I have an Excel sheet with approx. 3500 entries-

    I would like to create a query/search...whatever wherein a user could enter a zip code, choose a radius (20, 30, 50...miles) and the results would return all zip codes found within that radius.

    something that can be even accomplished w/in Excel?

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,351

    Re: Query needed - user enters zip code and chooses radius and matches against another tab

    Download the latitudes and longitudes for all zip codes from here:

    https://public.opendatasoft.com/expl...gitude/export/

    Then find the latitudes and longitudes for all your 3500 entries.

    The use the great circle formula from here:

    http://www.cpearson.com/excel/LatLong.aspx

    and calculate all the distances for your 3500 entries based on the select zip code, and then filter based on the selected radius.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Registered User
    Join Date
    04-15-2019
    Location
    Chicago, IL
    MS-Off Ver
    Office 365
    Posts
    51

    Re: Query needed - user enters zip code and chooses radius and matches against another tab

    wow! I will try and thanks - I'll report back

  4. #4
    Registered User
    Join Date
    04-15-2019
    Location
    Chicago, IL
    MS-Off Ver
    Office 365
    Posts
    51

    Re: Query needed - user enters zip code and chooses radius and matches against another tab

    First thing I need to do, in Google Sheets apparently, is to attach zip codes to the entries missing them. I have about 3000 and, in Sheets, and obviously running into the service invoked too many times in one day error - How can I work around this for free or paid?

    Here's my code:

    Please Login or Register  to view this content.
    Last edited by AliGW; 04-29-2019 at 04:23 PM.

  5. #5
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,351

    Re: Query needed - user enters zip code and chooses radius and matches against another tab

    Download the file - it's free, and it has all the zipcodes



    https://public.opendatasoft.com/expl...gitude/export/

  6. #6
    Registered User
    Join Date
    04-15-2019
    Location
    Chicago, IL
    MS-Off Ver
    Office 365
    Posts
    51

    Re: Query needed - user enters zip code and chooses radius and matches against another tab

    I need something that will take my list of addresses without zip codes and automatically find them - will this do that?

  7. #7
    Registered User
    Join Date
    04-15-2019
    Location
    Chicago, IL
    MS-Off Ver
    Office 365
    Posts
    51

    Re: Query needed - user enters zip code and chooses radius and matches against another tab

    and by the way that link does not work

  8. #8
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,351

    Re: Query needed - user enters zip code and chooses radius and matches against another tab

    Here are the files - Zip, City state, Lat and Long. You can find the zips from the City State of your addresses and go from there.

  9. #9
    Registered User
    Join Date
    04-15-2019
    Location
    Chicago, IL
    MS-Off Ver
    Office 365
    Posts
    51

    Re: Query needed - user enters zip code and chooses radius and matches against another tab

    Thanks! But is this something I could actually do in excel? My current record, for example, looks like this:

    4300 W Chicago Ave., Chicago, IL

    I added a column for ZIP in Google sheets and I will need a query/script to look at all 3000 addresses and populate the zip codes.

  10. #10
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,351

    Re: Query needed - user enters zip code and chooses radius and matches against another tab

    Are you using Excel or Google Sheets? I can tell you how to do it in Excel....

  11. #11
    Registered User
    Join Date
    04-15-2019
    Location
    Chicago, IL
    MS-Off Ver
    Office 365
    Posts
    51

    Re: Query needed - user enters zip code and chooses radius and matches against another tab

    Excel preferably!!! and thanks

  12. #12
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,351

    Re: Query needed - user enters zip code and chooses radius and matches against another tab

    This example is based on the third file that I uploaded - choose your file based on where you are actually located, to get the most zip code matches.
    Attached Files Attached Files

  13. #13
    Registered User
    Join Date
    04-15-2019
    Location
    Chicago, IL
    MS-Off Ver
    Office 365
    Posts
    51

    Re: Query needed - user enters zip code and chooses radius and matches against another tab

    Thanks! Was wondering how to download all of the zip files (so I have everything) into one excel sheet and have a simple table that looks like the attached- I could simply clean up the master list, input the addresses, and the zips would populate - Can you help?
    Attached Files Attached Files

  14. #14
    Registered User
    Join Date
    04-15-2019
    Location
    Chicago, IL
    MS-Off Ver
    Office 365
    Posts
    51

    Re: Query needed - user enters zip code and chooses radius and matches against another tab

    It works perfectly in Google Sheets using my script:

    function geo2zip(a) {
    var response=Maps.newGeocoder()
    .reverseGeocode(lat(a),long(a));
    return response.results[0].formatted_address.split(',')[2].trim().split(' ')[1];
    }
    function lat(pointa) {
    var response = Maps.newGeocoder()
    .geocode(pointa);
    return response.results[0].geometry.location.lat
    }
    function long(pointa) {
    var response = Maps.newGeocoder()
    .geocode(pointa);
    return response.results[0].geometry.location.lng
    }

    However, and as expected, I get the ERROR: Service Invoked Too Many Times for One Day" after about 100 lines - I'd gladly upgrade my account to allow me to run this script for the whole sheet but can't find any info on how to do so.

  15. #15
    Registered User
    Join Date
    04-15-2019
    Location
    Chicago, IL
    MS-Off Ver
    Office 365
    Posts
    51

    Re: Query needed - user enters zip code and chooses radius and matches against another tab

    I downloaded all the files and put them into 1 excel column. I am using the following formula:

    =MIN(IF($C$1:$C$531911=J7,IF($B$1:$B$531911=I7,VALUE($A$1:$A$531911))))

    The ZIP column is showing 0

    any ideas?

    My example attached

  16. #16
    Registered User
    Join Date
    04-15-2019
    Location
    Chicago, IL
    MS-Off Ver
    Office 365
    Posts
    51

    Re: Query needed - user enters zip code and chooses radius and matches against another tab

    Quote Originally Posted by Terrapin69 View Post
    I downloaded all the files and put them into 1 excel column. I am using the following formula:

    =MIN(IF($C$1:$C$531911=J7,IF($B$1:$B$531911=I7,VALUE($A$1:$A$531911))))

    The ZIP column is showing 0

    any ideas?

    My example attached
    apparently too big to attach but you get the idea I believe - Thanks

  17. #17
    Registered User
    Join Date
    04-15-2019
    Location
    Chicago, IL
    MS-Off Ver
    Office 365
    Posts
    51

    Re: Query needed - user enters zip code and chooses radius and matches against another tab

    Quote Originally Posted by Bernie Deitrick View Post
    This example is based on the third file that I uploaded - choose your file based on where you are actually located, to get the most zip code matches.
    Thanks! On the right track. How would I add all of the other files in an earlier post to this sheet to get results like you did in your example?

  18. #18
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,351

    Re: Query needed - user enters zip code and chooses radius and matches against another tab

    Yes - too big, whick is why I made 5 files out of the data.

    Note that you need to have entered that formula with Ctrl-Shift-Enter - it is an array formula. Note, too, that if nothing in C matches J7 and nothing in B matches I7, then the return will be 0. You can check the functionality by copying I7:J7 into B2:C2. Also, if you have text in A1 then the VALUE will return an error, so you may want to change all the $1 to $2.

    Also, there were only 45000 zip codes in all the files - not sure why you have 531911 rows of data - that will really slow down your calculations.

  19. #19
    Registered User
    Join Date
    04-15-2019
    Location
    Chicago, IL
    MS-Off Ver
    Office 365
    Posts
    51

    Re: Query needed - user enters zip code and chooses radius and matches against another tab

    Gotcha and I think I have it working pretty well now. My next step, as I have briefly mentioned, is to take my existing list of 3500 or so addresses without zip codes and assign zip codes to them - No radius functions needed - Can this do the same thing?

  20. #20
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,351

    Re: Query needed - user enters zip code and chooses radius and matches against another tab

    The array-formula that we last discussed - with the MIN - uses the city and state to return the zip code.

  21. #21
    Registered User
    Join Date
    04-15-2019
    Location
    Chicago, IL
    MS-Off Ver
    Office 365
    Posts
    51

    Re: Query needed - user enters zip code and chooses radius and matches against another tab

    Can you give me a quick example based on the attached? I would only need to clean up the C column in my 3500 entries and have the D column, in green find the ZIP. I assume I would need to import all of the 5 excel files previously downloaded and out them into this sheet too...
    Attached Files Attached Files

  22. #22
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,351

    Re: Query needed - user enters zip code and chooses radius and matches against another tab

    Your data is not well structured.

    To harvest some zips, use this in D2:

    =IFERROR(TEXT(VALUE(RIGHT(B2,5)),"00000"),"")

    and copy down. For those that return "" you will need to have a cell with the city and another with the state - which means you'll need to clean up your data set.

  23. #23
    Registered User
    Join Date
    04-15-2019
    Location
    Chicago, IL
    MS-Off Ver
    Office 365
    Posts
    51

    Re: Query needed - user enters zip code and chooses radius and matches against another tab

    Yeah - I know! The data was exported from smartsheet and it's the result of years of improper record keeping - I'll see what I can do and report back but many many thanks for so far

  24. #24
    Registered User
    Join Date
    04-15-2019
    Location
    Chicago, IL
    MS-Off Ver
    Office 365
    Posts
    51

    Re: Query needed - user enters zip code and chooses radius and matches against another tab

    That formula return a zip code if there is a zip in column B

    what I need is a zip populated based on Column C where the zip is missing.

    I assume I could have columns in the sheet which would house all the data we already downloaded (the 4500 or so rows) and the formula in D2 would compare against that?

  25. #25
    Registered User
    Join Date
    04-15-2019
    Location
    Chicago, IL
    MS-Off Ver
    Office 365
    Posts
    51

    Re: Query needed - user enters zip code and chooses radius and matches against another tab

    Like I said, this script works great in Google Sheets but times out after a few runs:

    function geo2zip(a) {
    var response=Maps.newGeocoder()
    .reverseGeocode(lat(a),long(a));
    return response.results[0].formatted_address.split(',')[2].trim().split(' ')[1];
    }
    function lat(pointa) {
    var response = Maps.newGeocoder()
    .geocode(pointa);
    return response.results[0].geometry.location.lat
    }
    function long(pointa) {
    var response = Maps.newGeocoder()
    .geocode(pointa);
    return response.results[0].geometry.location.lng
    }

    Is there any way to do something like that in Excel?

  26. #26
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,351

    Re: Query needed - user enters zip code and chooses radius and matches against another tab

    Create a column of formulas with this in Row 2:

    =TRIM(RIGHT(SUBSTITUTE(TRIM(C2)," ",REPT(" ",LEN(C2))),2*LEN(C2)))

    Then copy down to match your list in C, convert the formulas to Values and split the column using Text to columns delimited, with space and comma. That may find city and state for many of the rows where you don't have a zip code.

  27. #27
    Registered User
    Join Date
    04-15-2019
    Location
    Chicago, IL
    MS-Off Ver
    Office 365
    Posts
    51

    Re: Query needed - user enters zip code and chooses radius and matches against another tab

    Just not following sir, if possible can you take my attachment and do it on one row?

    The end result needs to look like...

    Subcontractor Mailing Address Full Address Zip Code

    1 4300 W Chicago Ave,. Chicago, IL 4300 W Chicago Ave., Chicago, IL 60601

    I need something in D2 that will pull zip codes from C2
    Attached Files Attached Files

  28. #28
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,351

    Re: Query needed - user enters zip code and chooses radius and matches against another tab

    Try this file, with some of the zip code list...
    Attached Files Attached Files

  29. #29
    Registered User
    Join Date
    04-15-2019
    Location
    Chicago, IL
    MS-Off Ver
    Office 365
    Posts
    51

    Re: Query needed - user enters zip code and chooses radius and matches against another tab

    Thanks much - I have burdened you enough and truly appreciate the help. I will continue to play around with this. The really odd thing is that I have the GSUITE paid version which allows my script to run 3200 times a day but I'm getting this error: Service invoked too many times in one day.geocode.Line 7 after it runs about 150 times - The scripts works great up until then. Maybe there is something in the script itself that is limiting?

    =geozipmh(D2) - Cell E2

    Script:

    function geozipmh(a) {
    var response=Maps.newGeocoder()
    .reverseGeocode(lat(a),long(a));
    return response.results[0].formatted_address.split(',')[2].trim().split(' ')[1];
    }
    function lat(pointa) {
    var response = Maps.newGeocoder()
    .geocode(pointa);
    return response.results[0].geometry.location.lat
    }
    function long(pointa) {
    var response = Maps.newGeocoder()
    .geocode(pointa);
    return response.results[0].geometry.location.lng
    }

  30. #30
    Registered User
    Join Date
    04-15-2019
    Location
    Chicago, IL
    MS-Off Ver
    Office 365
    Posts
    51

    Re: Query needed - user enters zip code and chooses radius and matches against another tab

    Quote Originally Posted by Bernie Deitrick View Post
    Try this file, with some of the zip code list...
    So...with this - can I just download the rest of the files in an earlier post, add them to column M-Q and have all of them?

  31. #31
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,351

    Re: Query needed - user enters zip code and chooses radius and matches against another tab

    Yes - just make sure that your formulas reference the new range of values or you may miss some.

+ 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. Delete tabs based on what the user chooses to keep
    By Fire24 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-11-2016, 04:32 PM
  2. how to get and use range that a user chooses randomly
    By ajan in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-22-2015, 05:14 PM
  3. [SOLVED] Modify code so user chooses files for wkbk1 and wkbk2-
    By Biased Historian in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-20-2013, 12:07 PM
  4. VB code to open a file that user chooses.
    By gshock in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 04-07-2013, 10:26 AM
  5. [SOLVED] VLOOKUP help aka if user chooses cell a1, then b1 equals x - Noob Alert
    By sidewaysscott in forum Excel General
    Replies: 5
    Last Post: 07-19-2012, 05:25 PM
  6. Selecting and aggregating data using user input radius
    By Fureak in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-13-2010, 06:38 PM
  7. Insert picture macro - user chooses
    By hannahw in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-23-2005, 11:59 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