Function Problems

Extract a Four-Character Code with an Excel Formula

Anum MushtaqAnum Mushtaq Nov 18, 2026 869 views

Question details

Extract four-character codes such as J950 and J942 from text when the preceding text varies in length.

Extract a Four-Character Code with an Excel Formula
Product
Microsoft Excel
Device & OS
not provided
Scenario
A column contains text followed by a four-character code, and the position of the code varies between rows.
Observed behavior
The desired result is a separate column containing the four-character code from each row.
Before you start

Check that each code begins immediately after the first space in its cell and is exactly four characters long. Identify the first source cell and an empty column for the results.

Solution 1Recommended

Use MID and FIND to extract the code after the first space

Use this formula when each code starts immediately after the first space, regardless of the length of the preceding text.

1
Select a result cell

If the source text starts in A1, click an empty cell such as B1.

2
Enter the formula

Type =MID(A1,FIND(" ",A1)+1,4) in B1 and press Enter. FIND locates the first space, and MID returns the next four characters.

3
Fill the formula down

Select B1 and drag its fill handle down alongside the remaining source rows.

Use MID and FIND to extract the code after the first space
Check the text pattern: The formula returns the four characters immediately after the first space; it does not verify that they form a code. If the code follows a different delimiter or later word, the formula must be adjusted.
Extract codes in WPS Spreadsheet

Extract Four-Character Codes in WPS Spreadsheet

Use the same MID and FIND formula in WPS Spreadsheet to extract codes that begin after the first space, then fill the formula down your data.

  1. 1. Open the spreadsheet: In WPS Spreadsheet, use Open to select the workbook containing your source text.
  2. 2. Enter the formula: Click an empty cell such as B1, enter =MID(A1,FIND(" ",A1)+1,4), and press Enter. Replace A1 if your source starts in another cell.
  3. 3. Apply it to other rows: Select the formula cell and drag its fill handle down beside the source data.
  4. 4. Save the workbook: Use File > Save or Save As to save the results in your preferred spreadsheet format.
Extract four-character codes with familiar spreadsheet functions.Open and edit Microsoft Excel XLS and XLSX files.Use WPS Office for free with a familiar spreadsheet interface.Fill formulas down a column to process multiple rows.
microsoft office alternative - wps office

Frequently Asked Questions

Why does the formula return a #VALUE! error?

FIND returns #VALUE! if it cannot find a space in the source cell. Check the text in A1 and confirm that it contains a space before the code.

What if there are multiple spaces before the code?

If the code follows the first word but extra spaces separate them, try =MID(TRIM(A1),FIND(" ",TRIM(A1))+1,4). TRIM removes leading spaces and reduces repeated spaces between words.

Will this formula find a code anywhere in the text?

No. It returns the four characters immediately after the first space. If the code appears elsewhere, use a consistent delimiter or a formula tailored to the text pattern.

Can I use the formula for a different cell?

Yes. Replace A1 in both places with the source cell, such as A2. When you drag the fill handle down, the cell references update for each row.