How to convert strings to Proper case in Apps Script?

Last updated: February 10, 2025

If you've worked with spreadsheets at a school or a company, you know that data can often be messy and not formatted correctly. One common issue that I've run into is that names are not capitalized correctly.

Google Sheets has a function called PROPER() that converts a string in your spreadsheet to Proper case, but unfortunately, there is no such function in Apps Script.

In this tutorial, you'll learn how to write a custom function to convert a string to Proper case.

/**
 * Convert a string to Proper case.
 
 * @param {string} str The string value to be converted.
 * @return The string value in Proper case.
 * @customfunction
*/
function PROPER_CASE(str) {
  if (typeof str != "string")
    throw `Expected string but got a ${typeof str} value.`;
  
  str = str.toLowerCase();

  var arr = str.split(/.-:?—/ );
  
  return arr.reduce(function(val, current) {
    return val += (current.charAt(0).toUpperCase() + current.slice(1));
  }, "");
}

Conclusion

In this tutorial, you learned how to write a custom function to convert a string to Proper case.

Thanks for reading!

DISCLAIMER: This content is provided for educational purposes only. All code, templates, and information should be thoroughly reviewed and tested before use. Use at your own risk. Full Terms of Service apply.

Small Scripts, Big Impact

Join 1,500+ professionals who are supercharging their productivity with Google Sheets automation

Exclusive Google Sheets automation tutorials and hands-on exercises
Ready-to-use scripts and templates that transform hours of manual work into seconds
Email updates with new automation tips and time-saving workflows

By subscribing, you agree to our Privacy Policy and Terms of Service