Text Formulas
Text Formulas
https://www.vertex42.com/blog/excel-formulas/text-formulas-in-excel.html
This workbook contains examples from the article "Text Manipulation Formulas in Excel." Regarding copyright
this file like a book. You may use the ideas and techniques and formulas explained here, but you may not repr
copy substantial portions from it, just as you would not do so with a book. Thank you. - Jon Wittwer
NEW: Now updated with LET and LAMBDA functions for the more complicated formulas.
EXAMPLES
Formula: =LEN(text)
Formula: =UPPER(text)
Formula: =LOWER(text)
Formula: =PROPER(text)
Formula: =EXACT(text,UPPER(text))
Formula: =EXACT(text,LOWER(text))
Formula: =EXACT(text,PROPER(text))
NOTE When used for concatenation, the & character is used as an "operator" rather than a function.
operators are +, -, and /.
The CONCAT and TEXTJOIN functions are also useful for concatenating strings, but are ava
365 subscription using Excel 2016 or Excel Online.
Formula: =CONCAT(A1:B1)
The UNICHAR and UNICODE functions are available in Excel 2013 or later.
Use CHAR(10) or UNICHAR(10) to return the line break character - and remember to toggle Word Wrap for th
of the line break.
You can create a progress bar using an in-cell bar via conditional formatting, but if that method is not available
reasons), you can represent the progress as a discrete fraction like n/10 and use REPT to create an in-cell pro
idea to use "empty" character symbols to represent the incomplete portion of the progress bar because the res
exactly into a cell like a conditional formatting progress bar.
Symbols Others
Complete: ⚑ ☒ , ⚑, 🏃
Incomplete: ⚐ ☐, ⚐
Today: ⌚ ⌚, ⌛, 🕓
Finish: 🏁
Formula: sprint = 14
progress = 24.5%
complete = ROUND(sprint*progress,0)
time = IF(TODAY()<start_date,0,IF(TODAY()>(start_date+sprint),sprint,TODAY()-start_date))
=REPT("⚑",MIN(time,complete)) & REPT("⚐",MAX(0,time-complete)) & "⌛" &
REPT("⚑",MAX(0,complete-time)) & REPT("⚐",sprint-MAX(time,complete)) & "🏁"
Why do some unicode characters like the watch ⌚ and hourglass ⌛ and finishline flag 🏁 change to other chara
formula? I have no idea.
Team Progress
A 40% ⚑⚑⚑⚑⚑⚑⚐⚐⚐⚐⚐⚐⚐⚐
B 73% ⚑⚑⚑⚑⚑⚑⚑⚑⚑⚑⚐⚐⚐⚐
C 65% ⚑⚑⚑⚑⚑⚑⚑⚑⚑⚐⚐⚐⚐⚐
D 56% ⚑⚑⚑⚑⚑⚑⚑⚑⚐⚐⚐⚐⚐⚐
If you also need to remove nonprinting characters such as tabs, newlines, etc. you can use the CLEAN functio
ASCII characters 0-31.
Formula: =CLEAN(text)
You can use the SUBSTITUTE function when cleaning up text if you need to remove other types of non-ASCII
replace the characters with normal spaces. Wrap the function within TRIM and CLEAN to remove extra space
characters. This is a good way to handle tabs (9) and newlines (10) and non-breaking spaces (160) so that yo
that should be separated by a space. The example below nests the SUBSTITUTE function multiple times to ge
and non-breaking spaces within one formula.
LAMBDA: v42_textCleanPlus
=v42_textCleanPlus(text)
Sometimes your text has special quote symbols that need to be changed to normal quotes. These special quo
’(146), “(147), ”(148). The normal double quotes is CHAR(34).
LAMBDA: v42_textFixSpecialQuotes
=v42_textFixSpecialQuotes(text)
Case Sensitive
Formula: =FIND(find_text,within_text,[start_num])
=FIND(" ","Tom Sawyer")
The [start_num] argument can come in handy if you want to find the position of the 2nd occurrence of text with
this by using a nested FIND or nested SEARCH formula, like this:
Formula: =SUBSTITUTE(original_text,old_text,new_text,[occurrence])
old_text new_text
Replace each occurrence: # ,
old_text new_text
Replace only the 2nd occurrence: # ,
When combined with FIND or REPLACE, you can use SUBSTITUTE to find the position of the Nth occurrence
another text string.
Formula: =MID(text,start_num,num_chars)
start_num num_chars
5 3
Formula: =REPLACE(text,start_num,num_chars,replace_text)
start_num num_chars
3 1
Formula: =LEFT(text,num_chars)
Formula: =RIGHT(text,num_chars)
Formula: =REGEXREPLACE(text,"[^a-zA-Z0-9]","")
Formula: =REGEXREPLACE(text,"[a-zA-Z0-9]","*")
Formula: =REGEXREPLACE(text,".(?=.{4})","*")
Prompt: How to I use REGEXREPLACE to remove all non-alphanumeric characters, except for spaces
LAMBDA: =L_COUNTCHAR(char,within_text)
Formula: =(LEN(text) -
LEN( SUBSTITUTE(text,string","") ) ) /
LEN(string)
LAMBDA: =L_COUNTCHAR(text,within_text)
It a space is not found, FIND will return an error, so you can wrap the formula with ISERROR to return the full
are found, like this:
I've wrapped the formula with IFERROR because if the name contains no spaces, I assume the name is only a
the empty string "". You could instead use IFERROR to return the original text value instead of "".
Office 365! The TEXTAFTER function makes this much simpler! The cool thing is that this function has an "
built in, so the following formula does the same thing as above.
Formula: =TRIM(MID(SUBSTITUTE(text,delimeter,REPT("
",LEN(text))),(word-1)*LEN(text)+1,LEN(text)))
=TRIM(MID(SUBSTITUTE(text,delimeter,REPT("
",LEN(text))),(word-1)*LEN(text)+1,LEN(text)))
Office 365! The TEXTSPLIT function makes this much simpler! TEXTSPLIT will convert a text string into an
then pick the nth column.
Formula: =INDEX(TEXTSPLIT(text,,row_delim),row_num)
LAMBDA: v42_textGetNthWord
=v42_textGetNthWord(text,delimiter,n)
REFERENCE http://www.mrexcel.com/forum/excel-questions/587534-text-columns-via-formula.html
REFERENCE https://exceljet.net/formula/extract-nth-word-from-text-string
To display the results within an array of cells, remember to use Ctrl+Shift+Enter. Use TRANSPOSE if you wan
of this formula in a row instead of a column.
Office 365! TEXTSPLIT can be used to convert a text string into an actual array. You can use VALUE,
SUBSTITUTE, and other text functions to clean up the data before or after converting to an arra
REFERENCE https://stackoverflow.com/questions/25316094/split-a-string-cell-in-excel-without-vba-e-g-for-a
The following function will split a text string into an array of separate characters.
Office 365! The SEQUENCE function makes this much simpler, without requiring a multi-cell array (uses th
instead)
If you wrap the function with CODE or UNICODE then you can display the numeric code for each character in
Office 365! With an Office 365 subscription, you can wrap the above functions with TEXTJOIN to display a
separated by a delimiter.
text Result
!"= 33,32,34,32,61
Using the above lambda
!"= Err:508
☆ Formula in Image for Blog Post "Text Manipulation with Excel Form
Start With
Result
REFERENCES
☆ Some references have been included above. See the support.office.com website for official documentation of
https://support.microsoft.com/en-us/office/text-functions-reference-cccd86ad-547d-4ea9-a065-7bb697c2a56e
© 2017-2024 Vertex42 LLC
plicated formulas.
of characters)
Text Result
onetwothree 11
Text Result
this text THIS TEXT
THIS TEXT this text
this text This Text
Text Result
THIS TEXT TRUE
this text TRUE
This Text TRUE
Hi World Hi World
Hi World #NAME?
A B #NAME?
ater.
d remember to toggle Word Wrap for the cell to see the effect
Value Result
Hello "Hello"
UND((1-progress)*10,0))
te+sprint),sprint,TODAY()-start_date))
me-complete)) & "⌛" &
MAX(time,complete)) & "🏁"
⚑⚑⚑⚑⚑⚐⚐⚐⚐⚐⚐⚐⚐
⚑⚑⚑⚑⚑⚑⚑⚑⚑⚐⚐⚐⚐
⚑⚑⚑⚑⚑⚑⚑⚑⚐⚐⚐⚐⚐
⚑⚑⚑⚑⚑⚑⚑⚐⚐⚐⚐⚐⚐
s, etc. you can use the CLEAN function which removes all
Text Result
Hi
HiWorld
World
Hi World Hi World
Text Result
Hi Hi World
World
Hi Err:509
World
Hi
Err:509
World
Text Result
“Hi ‘world!’ ” "Hi 'world!' "
hin a string
ion of a text string within another string. SEARCH is case
(the beginning of the string).
text Result
Jim A. Swift 7
original_text Result
1#2#3#4 1, 2, 3, 4
original_text occurrence Result
1#2#3#4 2 1#2, 3#4
egular Expression
XEXTRACT) are powerful new functions that let you harness
text Result
(123) 456-7890 1234567890
"Hello, World #42!" HelloWorld42
text Result
(123) 456-7890 (***) ***-****
123-00-4567 ***-**-****
text Result
1234 5678 9809 **********9809
umeric characters, except for spaces and periods, from a text string?
ust substitute " " with "," or ";" to count the number of commas
g within a string
g, then you can use a slightly modified version of the above
ng.
FT function and then use FIND to return the position of the first
d or name.
Name Result
Tom Sawyer Tom
Tom #VALUE!
Name Result
Tom Tom
Name Result
Tom Sawyer Tom
Todd Allen Smith Todd
Tom #NAME?
Tom Tom
Name Result
Tom Sawyer #NAME?
Todd Allen Smith #NAME?
Tom #NAME?
Name Result
Tom Sawyer #NAME?
Todd Allen Smith #NAME?
Tom #NAME?
and then calculate the length of the last name using LEN(text)-
eturn the last name, but if it is a name like "Todd Allen Smith"
Name Result
Tom Sawyer Sawyer
Todd Allen Smith Allen Smith
Name Result
Tom Sawyer Sawyer
Todd Allen Smith Allen Smith
Tom #NAME? (error expected)
Name Result
Tom Sawyer Sawyer
Todd Allen Smith Allen Smith
Tom #NAME? (error expected)
Name Result
Tom Sawyer #NAME?
Todd Allen Smith #NAME?
Tom #NAME? (error expected)
ames, we replace FIND(" ",text) with the position of the last
entioned above, then SUBSTITUTE the last space with
al character. You can use any character that you know won't
Name Result
Todd A. B. Smith Smith
Todd Smith Smith
Todd
Name Result
Todd A. B. Smith Smith
Todd Smith Smith
Todd #NAME?
Name Result
Todd A. B. Smith #NAME?
Todd Smith #NAME?
Todd #NAME?
TSPLIT will convert a text string into an array based on a delimiter. INDEX can
-text-columns-via-formula.html
ee"} that can be used within array formulas? First, start with
ITUTE(text,delimiter,"")))/LEN(delimiter)+1)))
N(text))), (ROW(INDIRECT("1:"&((LEN(text)-
))) -1) * LEN(text)+1, LEN(text)))
tring-cell-in-excel-without-vba-e-g-for-array-formula
aracters.
N(text_string))), 1) )
61 #N/A #N/A
Err:508
RECT("1:"&LEN(text)) ),1)) )
Text Manipulation
Excel Formulas