Build Your Own PROPER() Custom Apps Script Function to Capitalize Each Word

About this Tutorial

There's something wrong with PROPER() the google sheets function. Let's fix it by customizing our own TitleCase() function inside of Apps Script.

Featured Formulas

Video Transcript

0:00 Alright, so you have a text and you want to capitalize it, each and every, uh, word in that text. And do you see sort of a problem with this?
0:08 Uh, do you see on the left is the original and on the right is what's called title case or in Google Sheets term proper?
0:16 You'll see there's a difference between these two things. Uh, one of them is that there's an apostrophe S and then the S is capitalized.
0:25 But we're using proper which is the actual built-in function inside of abscr- uh not in abscr- in Google Sheets. It's uh one of the most used ones and it's capitalizing.
0:38 It's doing this wrong. It's not capitalizing the first character of every word. It's capitalizing after this apostrophe as well. But I created this.
0:48 Created my own where the only the first letter is capitalized, not after the apostrophes. And I'm going to show you how to do this and how to add a little bit extra stuff.
0:57 So go up to extensions, Apps Script. If you want to type this out yourself, go ahead. We're going to take, we're going to call it.
1:04 Function title. We're going to take some input text. That is the name of it. We can rename this any text if we want.
1:12 And not that it is literally text, but it is like any text. Uh, we're going to save that. We're going to take the words.
1:20 Which will split with just this little split with a space. So every space will be split. And then we're going to map a function where each and every word, we're going to get the character that's at zero, which is the very first character.
1:34 We're going to upcase it. And then we're going to, We're going to slice it and everything to lowercase and put them all together, put everything together in this join.
1:44 So that means if we have some improper capitalization, we don't have it here. It can be done here, right? This proper is doing that correctly, but we're also doing that, we're making sure that only the first character is capitalized, but we're also making sure that not after the apostrophe.
2:03 So this is what the title, this function title is doing. I'm to make it run like a custom function inside of Google Sheets, and all I have to do is add this little text at the beginning, which is at custom function.
2:22 I'm going to hit save, and now I'm going to copy and paste this. And if I hit equals T**** equal title, there it is, it's now showing up.
2:34 And now it shows me this uh input, any text, it has some other uh information if I want I can that there, but I just want to make it run like a native function, and it's doing that now.
2:45 And we can name this anything we want. Title, we can say title, each letter, each word, sorry, each word, not title.
2:56 we want. Capitalize each word. So hit save, make sure it's saved, and now instead of title, equals capitalize each word.
3:08 So we can name this anything we want. We can even create multiple of these. Then if we don't remember the name, title case maybe, or title case each word.
3:22 All of these are doing exactly the same. They all have at custom function, and now they'll all show up. So we can also rename title case.
3:31 We can also add title if we want. If we don't remember that it's fully title case, so we start typing equals title.
3:40 We have title, title case, title case each word. We have equals, capital, capital, capitalized each word there and they all work the same way because they're each the same app script.
3:50 And so we can create basically a better proper or a better function that already exists inside of Google Sheets and also I wanted to make sure you remember this.
4:00 You can create multiple app scripts and multiple functions with different names that do the exact same thing. If for some reason you may create an app script for a function that you have multiple names for and I think that's really awesome too.
4:13 Because this proper is not really, I've never heard. I've heard of this nomenclature proper. I always hear title case or headline case.
4:20 Headline this, right? If you want to create this function for creating headlines or capitalizing correctly headlines, maybe you want to call it headline case.
4:29 Whatever you want to do, you can now do that here. app script with this at custom function. I think really really cool.