Function Problems

Extract W320 from Text with an Excel MID Formula

Chanuka GeekiyanageChanuka Geekiyanage Dec 2, 2026 869 views

Question details

Extract a four-character product code such as W320 from a cell containing a longer description.

Extract W320 from Text with an Excel MID Formula
Product
Microsoft Excel
Device & OS
not provided
Scenario
A product description contains a space-separated code beginning with W, such as W320.
Observed behavior
The desired result is W320 from the text “VIETNAMESE CASHEW KERNEL W320 HSCODE 080132.”
Before you start

Place the source text in a cell, such as A1, and check that the code is a four-character word separated by spaces. The formula below finds the first matching four-character word beginning with W; it does not verify that the last three characters are digits.

Solution 1Recommended

Extract a space-separated W code with MID and SEARCH

Use this formula when another word, such as CASHEW, contains W before the product code.

1
Enter the source text

Place the product description in cell A1.

2
Enter the extraction formula

Select an empty cell, enter =MID(" "&A1&" ",SEARCH(" W??? "," "&A1&" ")+1,4), and press Enter.

3
Check the result

Confirm that the formula returns W320 for the example text. Drag the fill handle down to apply it to other rows.

Extract a space-separated W code with MID and SEARCH
How the match works: SEARCH uses question marks as single-character wildcards and is not case-sensitive. The added spaces also allow a code at the start or end of the cell. If another four-character word beginning with W appears first, it will be returned instead.
Extract product codes in WPS Spreadsheet

Extract W320 with MID and SEARCH in WPS Spreadsheet

Use the same MID and SEARCH formula in WPS Spreadsheet to extract a space-separated product code from a longer description.

  1. 1. Open the spreadsheet: Open WPS Spreadsheet and place the product description in cell A1.
  2. 2. Enter the formula: Select an empty cell and enter =MID(" "&A1&" ",SEARCH(" W??? "," "&A1&" ")+1,4).
  3. 3. Apply the formula: Press Enter to return W320, then drag the cell’s fill handle down to extract codes from additional rows.
  4. 4. Save the workbook: Choose File > Save As and select an Excel workbook format such as XLSX if you need to share it with Excel users.
Extract four-character W codes from product descriptionsOpen and edit Microsoft Excel XLSX filesApply the formula to multiple rows with the fill handleWork in a familiar spreadsheet interface
microsoft office alternative - wps office

Frequently Asked Questions

Why does searching for the first W not return W320?

In the example, CASHEW contains an earlier W. Use =MID(" "&A1&" ",SEARCH(" W??? "," "&A1&" ")+1,4) to find the first space-separated four-character word beginning with W instead.

What happens if there is no matching code?

SEARCH returns a #VALUE! error. To show a blank instead, use =IFERROR(MID(" "&A1&" ",SEARCH(" W??? "," "&A1&" ")+1,4),"").

Does the formula work if W320 is at the start or end of the text?

Yes. The formula adds a space to each end of the text before searching, so a four-character code at either boundary can match.

Does the formula require the last three characters to be numbers?

No. The three question marks match any three characters, so a different four-character word beginning with W could be returned if it appears first.