How to extract hashtags from text in Excel
Excel formula
=LET(w,TEXTSPLIT(A2," "),TEXTJOIN(" ",TRUE,FILTER(w,LEFT(w)="#","")))In Excel 365, split the text into words and keep the ones that start with #: =LET(w,TEXTSPLIT(A2," "),TEXTJOIN(" ",TRUE,FILTER(w,LEFT(w)="#",""))).
- Result on the example
- one result per row in
B2, filled down toB6 - Works in
- Microsoft 365 only
- Google Sheets
- Different formula, see below
See it work
The formula is already in B2, filled down to B6. Change any input and the result updates, or edit the formula to experiment.
How it works
LET names w, the words of the post from TEXTSPLIT. FILTER keeps the words whose first character is #, and TEXTJOIN joins them with spaces. The last argument of FILTER, "", is what to return when there are no hashtags, so "No tags here" gives a blank instead of #CALC!.
In Google Sheets, REGEXEXTRACT checks each word for a # followed by letters, digits or underscores, which also drops punctuation stuck to a tag.
=LET(w,TEXTSPLIT(A2," "),TEXTJOIN(" ",TRUE,FILTER(w,LEFT(w)="#","")))Result"#wfh #desksetup"
w{1 row × 5 cols} "New", "desk", "setup!", "#wfh", …A name defined in LET, or a named range.
A2"New desk setup! #wfh #desksetup"The value in A2.
TEXTSPLIT(A2," "){1 row × 5 cols} "New", "desk", "setup!", "#wfh", …TEXTSPLIT: Splits text across columns, and rows, at the delimiters you give.- text
A2"New desk setup! #wfh #desksetup" - col_delimiter
" "
- text
LEFT(w){1 row × 5 cols} "N", "d", "s", "#", …LEFT: Characters from the start of text.- text
w{1 row × 5 cols} "New", "desk", "setup!", "#wfh", …
- text
LEFT(w)="#"{1 row × 5 cols} FALSE, FALSE, FALSE, TRUE, …The = operator tests whether the two sides are equal.
FILTER(w,LEFT(w)="#",""){1 row × 2 cols} "#wfh", "#desksetup"FILTER: Rows of a range that meet every condition. #N/A when none match.- range
w{1 row × 5 cols} "New", "desk", "setup!", "#wfh", … - condition1
LEFT(w)="#"{1 row × 5 cols} FALSE, FALSE, FALSE, TRUE, … - condition2, ...
""
- range
TEXTJOIN(" ",TRUE,FILTER(w,LEFT(w)="#",""))"#wfh #desksetup"TEXTJOIN: Joins text with a delimiter between items.- delimiter
" " - ignore_empty
TRUE - text1
FILTER(w,LEFT(w)="#",""){1 row × 2 cols} "#wfh", "#desksetup"
- delimiter
LET(w,TEXTSPLIT(A2," "),TEXTJOIN(" ",TRUE,FILTER(w,LEFT(w)="#","")))"#wfh #desksetup"LET: Names values inside a formula.- name1
w{1 row × 5 cols} "New", "desk", "setup!", "#wfh", … - value1
TEXTSPLIT(A2," "){1 row × 5 cols} "New", "desk", "setup!", "#wfh", … - name2, value2
TEXTJOIN(" ",TRUE,FILTER(w,LEFT(w)="#",""))"#wfh #desksetup"
- name1
In Google Sheets
Google Sheets needs a different formula: =TEXTJOIN(" ",TRUE,ARRAYFORMULA(IFERROR(REGEXEXTRACT(SPLIT(A2," "),"^#\w+"),""))). On the same data it gives the same result. Here it is running in Google Sheets mode.
Other ways to do it
Each one was run on the same example sheet.
| Formula | Result | When to use it |
|---|---|---|
| =TEXTJOIN(" ",TRUE,FILTER(TEXTSPLIT(A2," "),LEFT(TEXTSPLIT(A2," "))="#","")) | #wfh #desksetup, #sale, … | The same without LET, splitting the post twice. |
Common mistakes
- Punctuation attached to a tag stays with it in the Excel formula: "#sale!" is returned as "#sale!". Remove punctuation first, or use the Google Sheets pattern.
- Hashtags written without a space before them, like "great#sale", aren't separate words and are missed.
Try it yourself
Same data, empty answer cell. Your formula is graded instantly, then re-checked on changed data, so a typed-in number won't pass.
Extract hashtags from text
B2, list the hashtags in the post (the words that start with #), separated by spaces. Fill down to B6.Questions
How do I count the hashtags in a post?
Count the # signs: =LEN(A2)-LEN(SUBSTITUTE(A2,"#","")).
How do I extract @mentions instead?
Change the test to LEFT(w)="@".
Checked by running on 2026-10-30: every formula and result on this page was calculated by the Spreadsheet Practice formula engine, in both Excel and Google Sheets modes.