Get Zip Code automatically from address in Google Sheets
Use Case Scenario:
Our Google Sheet contains hundreds of addresses without ZIP code and we would like to get the zip code for all of the addresses automatically.
Our tutorial on “How to Get Zip Code Automatically from Address” is just what you need! This guide will walk you through the simple steps to set up a function that automatically populates a column with ZIP codes based on address data. Whether you’re managing a customer database or organizing a mailing list, this tutorial will save you time and ensure accuracy in your work. Dive into the world of efficient data handling with our easy-to-follow tutorial!
1. Click on the cell that will display the Zip Code
2. Go to Extensions -> App Script
3. Copy and Paste the function below to your project
function getzip(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
}
4. Rename and Save your Project
5. Go back to your Google Sheet
6. In the selected cell, call the function by typing the function name and followed by the cell location of the address.
=getzip(A2)
7. The function will get the Zip Code from Google’s GeoLocation and display it in the cell.