How to Customize PROPER Function in Google Sheets (Creating a Headline Case)
Have you ever wanted to make all the words in your Google Sheet stand out? Here is an easy tutorial for capitalizing each word, just like a title!
Headline Case and Apostrophe Issue [FIXED]
Look at the two columns: ORIGINAL has the text we are working with, and TITLE CASE shows what happens when we use the PROPER function.
In cell B2, you might notice the "S" after the apostrophe is capitalized. That is not exactly what we want. Cell B3 shows a better way to format the text, keeping the lowercase letter after the apostrophe.
To break it down, Column B2 uses the automatic PROPER Function in Google Sheets, while B3 uses a customized formula using the Apps Script.
The Trick to Customize the PROPER Function (Code Included)
1. Click Extensions > Apps Script.
2. Enter the code into the script editor. When naming the function, replace title with a descriptive name of your choice.
function title(text) { var words = text.split(' '); var capitalizedWords = words.map(function(word) { return word.charAt(θ).toUpperCase() + word.slice(1).toLowerCase(); }); return capitalizedWords.join(' '); } |
3. To run your code like a built-in Google Sheets function. Simply add @customfunction before your code, then click Save.
/** * @customfunction */ function title(anyText) { var words = anyText.split(' '); var capitalizedWords = words.map(function(word) { return word.charAt(θ).toUpperCase() + word.slice(1).toLowerCase(); }); return capitalizedWords.join(' '); } |
4. Let us run the code. Start by selecting the empty cell where you would like the capitalized text to appear. Type an equal sign (=) followed by the function name. In this case, we type =title in the cell. Google Sheet will give you suggestions as you type, making it easier for you to find the right function.
BONUS: Do you struggle remembering function names? Or do multiple people want to use the function, but each of them calls it something different?
Here are more tips to make multiple names for the same function for easy recall.
Don't forget a function ever again. (Give your custom formulas more than one name)
1. Simply Copy and Paste the same code and rename the title with your choice. Click Save.
/** * @customfunction */ function CapitalizeEachWord(anyText) { var words = anyText.split(' '); var capitalizedWords = words.map(function(word) { return word.charAt(θ).toUpperCase() + word.slice(1).toLowerCase(); }); return capitalizedWords.join(' '); } /** * @customfunction */ function titleCase(anyText) { var words = anyText.split(' '); var capitalizedWords = words.map(function(word) { return word.charAt(θ).toUpperCase() + word.slice(1).toLowerCase(); }); return capitalizedWords.join(' '); } /** * @customfunction */ function titleCaseEachWord(anyText) { var words = anyText.split(' '); var capitalizedWords = words.map(function(word) { return word.charAt(θ).toUpperCase() + word.slice(1).toLowerCase(); }); return capitalizedWords.join(' '); } |
2. Start your search with an equal sign (=) and the function name to see if the names work.