Key Takeaways
- Split contact names, clean emails and format phones with a free method you can try in Google Sheets before you install anything, so every rule can be checked on your own data first.
- The Apps Script examples read and write the sheet once.
- Formula alternatives cover the common case while the script handles the awkward edges of a real export.
- Every example keeps its source columns.
Introduction
Split a contact name, clean emails and format phones in Google Sheets and the work is finished before a CRM sees the file. Three fields cause more rejections than any others: a name in one column, an email with a mistyped domain and a phone number in local format.
This guide gives you three small Apps Script functions that work on the active sheet. One splits a name into given and family names, one normalises email addresses and one converts phone numbers to E.164. Each writes beside the source so you can audit the result.
What Each Normaliser Changes
| Field | Input example | Output example |
|---|---|---|
| Name | Curie, Marie | Marie and Curie in separate columns |
| Marie.Curie@GMIAL.COM | marie.curie@gmail.com | |
| Phone | 020 7946 0958 | +442079460958 |
Notice what the functions do not do. They do not guess a missing surname, verify a mailbox or decide whether a phone number is still active. They apply a fixed rule to every row, which is exactly what a repeatable cleanup needs.
The Ready-Made Apps Script
Open Extensions then Apps Script in your spreadsheet, paste the code below, save it and run the function you need. Authorise the script when Google asks. Each function reads the active sheet and writes new columns to the right of the existing data.
/** Splits column A into given names, family name and suffix in columns B to D. */
function splitNamesInSheet() {
const sheet = SpreadsheetApp.getActiveSheet();
const values = sheet.getDataRange().getValues();
const output = [["Given", "Family", "Suffix"]];
for (let r = 1; r < values.length; r += 1) {
const raw = String(values[r][0] || "").trim().replace(/\s+/g, " ");
let given = "";
let family = "";
let suffix = "";
if (raw.indexOf(",") !== -1) {
const parts = raw.split(",");
family = parts[0].trim();
given = parts.slice(1).join(" ").trim();
} else {
const words = raw.split(" ");
const suffixes = ["Jr", "Sr", "II", "III", "IV"];
const last = words[words.length - 1];
if (suffixes.indexOf(last) !== -1) {
suffix = last;
words.pop();
}
family = words.length > 1 ? words.pop() : "";
given = words.join(" ");
}
output.push([given, family, suffix]);
}
sheet.getRange(1, 2, output.length, 3).setValues(output);
}
/** Lowercases emails in column A and corrects common domain typos into column B. */
function normaliseEmailsInSheet() {
const sheet = SpreadsheetApp.getActiveSheet();
const values = sheet.getDataRange().getValues();
const typos = {
"gmial.com": "gmail.com",
"gmai.com": "gmail.com",
"hotmial.com": "hotmail.com",
"yahooo.com": "yahoo.com",
"outlok.com": "outlook.com",
};
const output = [["Normalised email"]];
for (let r = 1; r < values.length; r += 1) {
let email = String(values[r][0] || "").trim().toLowerCase();
const at = email.indexOf("@");
if (at !== -1) {
const domain = email.slice(at + 1);
if (typos[domain]) {
email = email.slice(0, at + 1) + typos[domain];
}
}
output.push([email]);
}
sheet.getRange(1, 2, output.length, 1).setValues(output);
}
/** Formats phone numbers in column A as E.164 strings in column B. */
function formatPhonesInSheet() {
const sheet = SpreadsheetApp.getActiveSheet();
const values = sheet.getDataRange().getValues();
const output = [["Formatted phone"]];
for (let r = 1; r < values.length; r += 1) {
let raw = String(values[r][0] || "").trim();
if (!raw) {
output.push([""]);
continue;
}
let digits = raw.replace(/\D/g, "");
if (raw.indexOf("00") === 0) {
digits = digits.slice(2);
output.push(["+" + digits]);
continue;
}
if (raw.indexOf("+") === 0) {
output.push(["+" + digits]);
continue;
}
if (digits.length === 11 && digits.indexOf("0") === 0) {
output.push(["+44" + digits.slice(1)]);
} else if (digits.length === 10 && digits.indexOf("0") !== 0) {
output.push(["+1" + digits]);
} else {
output.push(["needs review"]);
}
}
sheet.getRange(1, 2, output.length, 1).setValues(output);
}
All three functions use getValues() to read the sheet once and setValues() to write once. That keeps the run fast on a long list. The maps at the top are plain objects, so you can add another typo or abbreviation without changing the loop.
Run the functions in order if you want a single clean table: split names first, normalise emails second and format phones third. Each step leaves the original column untouched.
A Worked Example
| Source name | Source email | Source phone | Result |
|---|---|---|---|
| Curie, Marie | Marie.Curie@GMIAL.COM | 020 7946 0958 | Marie Curie, marie.curie@gmail.com, +442079460958 |
| Isaac Newton | isaac@orbitra.co | +1 415 555 0132 | Isaac Newton, isaac@orbitra.co, +14155550132 |
| Rosalind Franklin | rosalind@hotmial.com | 123 | Rosalind Franklin, rosalind@hotmail.com, needs review |
The third row shows the deliberate limit. A three digit phone number cannot be turned into a valid E.164 number, so the function leaves a clear marker rather than inventing a country code.
Formula Alternatives
For a one-off list you can do part of the work without opening the script editor.
Lowercase and trim an email:
=LOWER(TRIM(A2))
Correct a common domain typo:
=REGEXREPLACE(LOWER(A2),"@gmial\.com$","@gmail.com")
Extract a first name from a single word name:
=IFERROR(INDEX(SPLIT(TRIM(A2)," "),1),"")
Strip phone punctuation into digits only:
=REGEXREPLACE(A2,"\D","")
These formulas cover the common case. The script is better when names arrive in two formats, phone numbers come from several countries or the same cleanup runs every week.
Where the Simple Rules Stop
Name splitting cannot resolve every cultural convention. A surname with two words, a particle such as van or de, and a suffix such as Jr all need a rule that matches your list. The comma form is the safest input because the separator is unambiguous.
Email typo correction only covers a short dictionary. It will not spot a misspelled company domain that looks plausible. For domain level checks, use the email cleaning guide and treat a domain change as a suggestion rather than a fact.
Phone formatting is not phone validation. A number with fifteen digits can still be disconnected. The rule makes the format consistent so a CRM or a verification service has something clean to work with.
Clean the Three Fields First
Names, emails and phone numbers travel through almost every system. Normalising them once in Google Sheets saves repeated decisions downstream. Use the formulas for a single file and the script for a list that comes back every week.
When the same person appears with a slightly different name across two exports, the next step is matching rather than formatting. Flookup Data Wrangler scores those near-duplicate rows inside the sheet and lets you review each merge before you accept it.
Frequently Asked Questions
Can I split a name stored as Last, First?
Yes. The script checks for a comma first and swaps the two parts. Without a comma it treats the last word as the surname and the rest as the given names.
What does the email normaliser actually change?
It trims spaces, lowers the whole address and corrects a short list of common domain typos such as gmial and hotmial. It does not check whether the mailbox exists.
Which phone numbers become E.164?
Numbers with 7 to 15 digits are kept. A leading 00 becomes a plus, a UK number starting with 0 becomes 44 and a ten digit US number gains the country code 1.
Do I need to keep the original columns?
Yes. The script writes to columns beside the source, so you can compare the result with the original value and change a rule if it gets something wrong.
Can I use formulas instead of Apps Script?
For simple cases yes. LOWER and TRIM handle emails, REGEXEXTRACT handles a first name and REGEXREPLACE strips phone punctuation. The script handles the edge cases in one pass.