Can you convert an address to a zip code in a spreadsheet?

Google spreadsheets has a series of functions for external data. If you can find (or create) a site which does the lookup by passing parameters, you could put a formula similar to this in:

Cell A1 (Address): 123 Main St
Cell B1 (City): Springfield
Cell C1 (State): MO

Cell D1 (combined address): =concatenate(A1,B1,C1)

Cell E1 (imported zip code): 
   =importData(concatenate("http://zipfinder.com/search?addr=",D1))

This is a hypothetical idea. The concatenate, importData and other functions for external data exist in Google Spreadsheets. "zipfinder.com" does not exist. There are lots of sites which will help you find a zip code from an address. The tricky part is finding one which accepts address data in the URL and returns something simple enough for Google Spreadsheets to use.


You can write a custom Apps Script function with the Google Maps service, using a similar approach to this answer. To do this, open Tools...Script editor... and paste this function in:

function getZIP(address) {
  var geo = Maps.newGeocoder().geocode(address);
  var resultComponents = geo.results[0].address_components;
  for (var i = 0; i < resultComponents.length; i++) {
     if (resultComponents[i].types.indexOf('postal_code') > -1) {
       return resultComponents[i].long_name;
    }
  }
}

You can then call this in a spreadsheet cell, for example, it correctly returns 20500 for the White House:

=getZIP("1600 Pennsylvania Ave. NW, Washington, DC")

Unlike some other approaches, it also works for non-US locations, e.g. it correctly returns 75007 for the Eiffel Tower:

=getZIP("Champ de Mars, 5 Avenue Anatole France, Paris, France")