Zip code Formatter formula

Zip code formatter is a custom formula in Google Sheets that formats a given zip code into the standard format of the country. For example, in the United States, the standard format for a zip code is 5 digits, whereas in Canada, it is a combination of letters and digits.

Here is an example code for a zip code formatter custom formula in Apps Script:

function formatZipCode(zipCode, country) {
  if (country == "US") {
    return zipCode.toString().padStart(5, "0");
  } else if (country == "Canada") {
    return zipCode.toUpperCase().replace(/ /g, "");
  } else {
    return "Invalid country";

This function takes two arguments: the zip code and the country. It then checks the country and applies the corresponding formatting. For US, it uses the padStart() method to add leading zeros to make the zip code 5 digits. For Canada, it uses the toUpperCase() method to convert the zip code to uppercase and replace() method to remove any spaces.

For example, if you have a zip code in cell A1 and the country in cell B1, you can use the custom formula =formatZipCode(A1, B1) to format the zip code in the standard format for the country.

This custom formula can save time and ensure consistency in formatting when dealing with large amounts of data that include zip codes from different countries.