Extract a Four-Character Code with an Excel Formula
Question details
Extract four-character codes such as J950 and J942 from text when the preceding text varies in length.

- 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.
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.
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.
If the source text starts in A1, click an empty cell such as B1.
Type =MID(A1,FIND(" ",A1)+1,4) in B1 and press Enter. FIND locates the first space, and MID returns the next four characters.
Select B1 and drag its fill handle down alongside the remaining source rows.

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. Open the spreadsheet: In WPS Spreadsheet, use Open to select the workbook containing your source text.
- 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. Apply it to other rows: Select the formula cell and drag its fill handle down beside the source data.
- 4. Save the workbook: Use File > Save or Save As to save the results in your preferred spreadsheet format.

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.




