Spreadsheet Practice

How to extract the last N characters from a cell in Excel

Formula (Excel and Google Sheets)

=RIGHT(A2,$E$1)

Use =RIGHT(A2,4) to return the last 4 characters, or =RIGHT(A2,$E$1) with the count in a cell.

Result on the example
one result per row in B2, filled down to B6
Works in
Every current version
Google Sheets
Same formula

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

RIGHT counts characters from the end of the text, so it works whatever the length of the rest. The result is text, which keeps the leading zero in "0043".

=RIGHT(A2,$E$1)

Result"4421"

  1. A2"ACCT-000184421"

    The value in A2.

  2. $E$14

    The value in E1.

  3. RIGHT(A2,$E$1)"4421"

    RIGHT: Characters from the end of text.

    • textA2"ACCT-000184421"
    • num_chars$E$14

In Google Sheets

The same formula works in Google Sheets: =RIGHT(A2,$E$1). We ran it in Google Sheets mode on the same data and it returns the same results.

Other ways to do it

Each one was run on the same example sheet.

FormulaResultWhen to use it
=MID(A2,LEN(A2)-$E$1+1,$E$1)4421, 3307, 1186…The same with MID: start N-1 characters before the end.

Common mistakes

  • Trailing spaces count as characters, so "4421 " returns "421 ". Use RIGHT(TRIM(A2),4) on imported data.
  • Long account or card numbers typed as numbers lose digits after 15. Store them as text before extracting.

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 last N characters from a cell

In B2, return the last N characters of the account, where N is in E1, and fill down to B6.

Questions

How do I turn the result into a number?

Wrap it in VALUE: =VALUE(RIGHT(A2,4)). Leading zeros are dropped.

How do I show only the last 4 digits and mask the rest?

Use =REPT("*",LEN(A2)-4)&RIGHT(A2,4).

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.