Spreadsheet Practice

How to extract the file extension from a file name in Excel

Excel formula

=TEXTAFTER(A2,".",-1,,,"")

Take the text after the last dot: =TEXTAFTER(A2,".",-1,,,""). The last argument returns blank for names with no extension.

Result on the example
one result per row in B2, filled down to B8
Works in
Microsoft 365 only
Google Sheets
Different formula, see below

See it work

The formula is already in B2, filled down to B8. Change any input and the result updates, or edit the formula to experiment.

How it works

File names can contain several dots, so the extension is what follows the last one: instance -1. When there is no dot at all, TEXTAFTER would return #N/A; its sixth argument, "", returns a blank instead.

=TEXTAFTER(A2,".",-1,,,"")

Result"xlsx"

  1. A2"q3-summary.xlsx"

    The value in A2.

  2. -1-1

    Makes the value negative.

  3. TEXTAFTER(A2,".",-1,,,"")"xlsx"

    TEXTAFTER: Text after a delimiter.

    • textA2"q3-summary.xlsx"
    • delimiter"."
    • instance_num-1-1
    • match_mode(omitted)
    • match_end(omitted)
    • if_not_found""

In Google Sheets

Google Sheets needs a different formula: =IFERROR(REGEXEXTRACT(A2,"\.([^.]+)$"),""). 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.

FormulaResultWhen to use it
=IFERROR(RIGHT(A2,LEN(A2)-FIND("*",SUBSTITUTE(A2,".","*",LEN(A2)-LEN(SUBSTITUTE(A2,".",""))))),"")xlsx, xlsx, pdf…Works in every version: count the dots, mark the last one with *, and take everything to its right.

Common mistakes

  • Taking the text after the first dot turns "Budget 2026.final.xlsx" into "final.xlsx".
  • Double extensions like .tar.gz return only "gz".
  • Extensions come in mixed case (JPG, jpg). Wrap in LOWER before counting or grouping by type.

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 the file extension from a file name

In B2, extract the file extension (the text after the last dot) and fill down to B8. Leave it blank when there is no dot.

Questions

How do I include the dot?

Join it back on: ="."&TEXTAFTER(A2,".",-1).

How do I count files by type?

Count the extension column: =COUNTIF(B2:B8,"pdf").

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.