# How to extract hashtags from text in Excel

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)="#",""))).

**Excel:** `=LET(w,TEXTSPLIT(A2," "),TEXTJOIN(" ",TRUE,FILTER(w,LEFT(w)="#","")))` (Microsoft 365 only)

**Google Sheets:** `=TEXTJOIN(" ",TRUE,ARRAYFORMULA(IFERROR(REGEXEXTRACT(SPLIT(A2," "),"^#\w+"),"")))`

## Example

Sample data (row 1 is the header):

| A | B |
| --- | --- |
| Post | Hashtags |
| New desk setup! #wfh #desksetup |  |
| Spring sale starts today #sale |  |
| No tags here |  |
| #oak #walnut #ash finishes now in stock |  |
| Back to school #students #deals #sale |  |

Formula in B2, filled to B6: `=LET(w,TEXTSPLIT(A2," "),TEXTJOIN(" ",TRUE,FILTER(w,LEFT(w)="#","")))`

Result: #wfh #desksetup; #sale; ; #oak #walnut #ash; #students #deals #sale

## 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.

## Other ways

- `=TEXTJOIN(" ",TRUE,FILTER(TEXTSPLIT(A2," "),LEFT(TEXTSPLIT(A2," "))="#",""))`: 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.

## 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)="@"`.

Every formula and result on this page was checked by running it in the Spreadsheet Practice formula engine on 2026-10-30.

Source: https://spreadsheetpractice.com/formulas/extract-hashtags-from-text
