User:Caileigholdroyd/Sandbox/Capitalize Titles

Video Link

1. Open your Google Sheets document.

2. Click on "Extensions" in the menu and select "Apps Script."

3. In the Apps Script editor, replace any existing code with the following code: /** * Capitalize text as it should be for a book title. * * @param {string} input The text to capitalize. * @return {string} The capitalized text. * @customfunction */ function CAPITALIZE_BOOK_TITLE(input) { if (input === null || input === "") { return ""; }

// Split the input text into words. var words = input.split(" "); var capitalizedWords = [];

// Capitalize each word, taking care to lowercase certain small words. for (var i = 0; i < words.length; i++) { var word = words[i].toLowerCase;

if (i === 0 || !["a", "an", "the", "and", "but", "for", "nor", "or", "so", "yet", "at", "by", "in", "of", "on", "to", "up", "as", "with"].includes(word)) { word = word.charAt(0).toUpperCase + word.slice(1); }

capitalizedWords.push(word); }

// Join the capitalized words back together. var capitalizedText = capitalizedWords.join(" ");

return capitalizedText; }

4. Save the script by clicking the floppy disk icon or pressing Ctrl + S.

5. In a cell, type =CAPITALIZE_BOOK_TITLE(A1) (assuming the text you want to capitalize is in cell A1).

6. Press Enter, and the function will capitalize the text in the specified cell as it should be for a book title.

7. Highlight the cell and drag down to the bottom of what you need capitalized.