It is almost 3:30 am now, I stayed awake for last 23 hours so that Excel School 2 can be ready for rolling. But that is no excuse for not having a post here. So here it goes.
Excel has formulas for converting a bunch of text to UPPER, lower and Proper Cases. But not a formula to convert o Sentence case. So, today we will learn a simple formula tip to convert text to sentence case (ie, First letter capital).
Assuming your text is in C2, the formula is,
=UPPER(LEFT(C2,1))&MID(LOWER(C2),2,999)
How the formula works?
It is converting first letter of C2 to upper case [UPPER(LEFT(C2,1))
] and lower case of rest of C2 [MID(LOWER(C2),2,999)
]
The 999 portion is the secret code to unlock ninja features of MID formula.
Well, I am kidding of course, the 999 is just a cop-out to say give me rest of the C2, I don’t know the length of it. (of course, 999 would fail if your text actually has more than 1000 chars. In that case, just use 9999 or whatever large number you fancy.)
Another formula:
=SUBSTITUTE(LOWER(C2),CHAR(CODE(C2)),UPPER(CHAR(CODE(C2))),1)
PS: As you can guess, the above formulas assume that C2 has one sentence. If C2 has a whole paragraph, then I would really need a sandwich before thinking about that problem.
How do you convert cases using Excel?
Please share your tips using comments.
Read a quick tip, become awesome in excel in less than 5 seconds.
27 Responses to “Convert Text to Sentence Case using Excel Formulas [Quick Tips]”
Interesting post. I can't think of a neat way to get a single formula to produce initial sentence capitals for an indefinite number of sentences contained in a single cell (but I bet SOMEONE can).
As a workaround, if you actually had this situation - i.e. lots of multi-sentence paragraphs, with each paragraph in a cell of its own - then what you could do is use text to columns to isolate each sentence into a cell of its own, and apply your formula to each single-sentence cell.
Then, if you really wanted to, you could string all the sentences back into one single paragraph cell. BUT, once you have split them up, you would probably be better off keeping all the sentences separate.
You could use LEN(C2)-1 for the length of the text string minus the first character. That's better then trying to fudge it with a large numeral.
=UPPER(LEFT(C2,1))&LOWER(RIGHT(C2,LEN(C2)-1)) will get rid of the 999 variable.
OK Had a quick think about multiple sentences. Using PROPER and SUBSTITUTE gives an answer (I think. I haven't tested fully)
=SUBSTITUTE(SUBSTITUTE(PROPER(SUBSTITUTE(SUBSTITUTE(LOWER(C12),". ","9z9")," ","zxz")),"9Z9",". "),"zxz"," ")
PROPER capitalizes first letter in a string and any letters that follow any character other than letter. So we use substitute to build the logic (using strings that can be replaced ie not common combinations.
Sorry it's a bit garbled. Give it a try. Write multiple sentences in C12
In principle, this is difficult to do for *all* sentences because Excel has no recursion or regular expressions. You could use VBA, or export the sentences to a text file and process them with your favourive regular expression language.
If you really need to do this in Excel (and assuming that all sentences end with a period followed by a blank), you find the first period followed by a blank, substitute that by a placeholder (I used "#"), and uppercase the letter after that.
The following example assumes that the original text is in C2.
=SUBSTITUTE(C2,". "&MID(C2,SEARCH(". ",C2)+2,1),"#"&UPPER(MID(C2,SEARCH(". ",C2)+2,1)))
Then you iterate by copying the formula to the right (or downwards, as appropriate) until no more substitutions can be done.
Then you replace all "#" in the final result by ". "
=SUBSTITUTE(C5;"#";". ")
@Andy.. Brilliant stuff.. Took me some time to figure it out. (also, I didnt know PROPER("a1b2c3") will be A1B2C3. ) Thank you so much for sharing it here.
@Gregor.. I would imagine pasting the whole thing in to MS Word, sentence casing it and then pasting back to Excel, If I ever need to do that. It is much faster and easier. Also, check Andy's formula above to understand a simpler (albeit geekier) version.
@John, Andy: Technically, 999 should be as fast or even slightly faster than len() approach. Although it is slightly difficult to explain.
@Andy,
Just to point out, your formula will only work for sentences that end with a period... it won't work correctly for sentences ending with a question mark or exclamation point, nor will it work correctly for titled names such as Dr. Who or Mrs. Jones.
May be dangerous to use because of other words that need to maintain their uppercasedness (is that a word?) But it's a good solution for small quantities of data that would be easy to proof. Cheers!
@Rick Yes it would need a period and wouldn't work with other endings, nor would it work with names or possibly even product code id's or Klingon. As mentioned previously excel is probably not the best tool for the job. Just proves the point that a lot of things can be done in excel just maybe not optimally.
@Chandoo thanks for the props. It's an interesting case of exploring native excel functionality to push the envelope.
@Andy - I was pretty sure you already knew the limitation of the formula; I posted my comments for completeness sake, that is, more for the reader's of the blog than for you. As for Excel (formulas) not being the best tool for the job... I'm not so sure VB is either. This is a very hard problem to code for because of all the exceptions that would have to be accounted for. Taking care of the punctuation at the end of sentences would not be too hard to code for, nor would name introducers (like Dr., Mr., etc.) as long as they are all identified beforehand so they could be coded for; but you raise an excellent point about product code IDs, and I would add company names to that as well (think IBM for example). As for Klingon, I don't speak it, so I don't know for sure if that could be coded for or not. By the way, I do agree with Chandoo... your substitution approach is clever, indeed; but, unfortunately, the underlying problems with the task are just too much for any formula approach I'm afraid.
@ Rick - Just reread my reply and I didn't mean to sound facetious. My point was as you say, it'd be difficult to cope with all exceptions. Even wordprocessors fail at this at some point. I don't speak Klingon either, just a geek dialect of Excel! I find these type of problems, while not fully solvable, interesting for practice and discovery, and I love the fact that there is always more than one way to solve a problem in Excel. Maybe Chandoo could have a regular Excel mini challenge on the blog?
@Andy.. I like the idea of challenges. I have seen that community is vibrant on posts where I pose a challenge or leave some homework. I will try to a challenge once every 2-3 weeks.
Excellent. This will save me lots of time.
I have an article about case changing in Excel:
http://www.codeforexcelandoutlook.com/excel-vba/case-changing-in-excel/
@JP.. very interesting link. Thank you for sharing it with us.
[...] June 17, 2010 at 5:03 PM | Posted in General | Leave a Comment Tags: formulas, letter-case Chandoo brings up an interesting problem: How do you convert and fix the letter case in a sentence, using [...]
Hello Chandoo, may I know if there is a formula to remove a comibination of number and text in one cell : MY-9876543. For example removing "MY-" in one cell.
@BG2 Try =Right(YourCell,Len(YourCell)-Find("-",YourCell))
whoa... thanks Hui. This is really helpful. 😀
You make my day!!!
[...] adding realtime scores updated from the web by visiting Realtime World Cup Scores.Sentence CaseIn Convert to Sentence Case, Chandoo provides a formula for converting to sentence case (that is, first word capitalizes, the [...]
[...] adding realtime scores updated from the web by visiting Realtime World Cup Scores.Sentence CaseIn Convert to Sentence Case, Chandoo provides a formula for converting to sentence case (that is, first word capitalizes, the [...]
Thank you so much for the tip. It has saved me HOURS of work, and when you think about it, it is so logical!! thanks again.
This rocks!! HUGE time saver. thank you!
If i want to change whole column text in upper case at a time then how should i do this? e.g  In  Name column  farukh,samreen like this one by one many names then i want that name convert it into FARUKH,SAMREEN etc.
how can convert lower/uppercase to other sentence or number. example
a = up
A = down.
so how can I convert lower case a to up & upper A to down
Super... Thankyou for saving my time & lovely tip.. 🙂
It's almost 2018 and this is still the solution. No new formula in Excel to handle this.