logo
search
Function Problems

How to Combine VLOOKUP or XLOOKUP with TEXTBEFORE in Excel

John WilsonJohn Wilson Sep 28, 2026 869 views

Question details

The user needs to combine VLOOKUP or XLOOKUP with text extraction functions like TEXTBEFORE, but encounters mismatch errors between text and numeric data types.

How to Combine VLOOKUP or XLOOKUP with TEXTBEFORE in Excel
Product
Excel
Device & OS
not provided
Scenario
Extracting specific characters from a string using TEXTBEFORE or TEXTAFTER and immediately using that result as the lookup value in an XLOOKUP or VLOOKUP formula.
Observed behavior
The lookup function fails to find a match and returns an error because TEXTBEFORE extracts values as text strings, which do not match the numeric format of the lookup array.
Before you start

Check your source data to determine if the lookup array contains numbers or text. Identifying the data type difference is the key to resolving this formula error.

Solution 1Recommended

Convert the Lookup Range to Text within the Formula

Append an empty string to your lookup array to force Excel to treat the numeric lookup values as text, matching the output of TEXTBEFORE.

Since TEXTBEFORE always outputs a text string, looking up this text against a range of numbers will fail. By appending an ampersand and empty quotes to the lookup range, you instantly convert all numbers in that range to text within the formula's memory.

1
Select the target cell

Click on the cell where you want the final lookup result to appear.

2
Draft the XLOOKUP formula

Type the beginning of your XLOOKUP formula using TEXTBEFORE as the lookup value, for example: =XLOOKUP(TEXTBEFORE(E2,"_"),

3
Modify the lookup array

Enter your lookup range and append &"" to it. For example, $A$1:$A$22&"".

4
Complete the formula

Add your return array and close the parentheses. The complete formula should look like: =XLOOKUP(TEXTBEFORE(E2,"_"),$A$1:$A$22&"",$B$1:$B$22).

5
Press Enter

Press Enter to calculate the result. The formula will now correctly match the text output to the modified text range.

Convert the Lookup Range to Text within the Formula
Dynamic Array Support: Appending an empty string to an array (e.g., $A$1:$A$22&"") creates a dynamic text array. This method is fully supported by XLOOKUP without requiring Ctrl+Shift+Enter.
Efficient Data Management

Use WPS Spreadsheet to Combine Advanced Lookup and Text Functions

WPS Spreadsheet provides powerful dynamic array capabilities, allowing you to easily combine XLOOKUP with text extraction functions like TEXTBEFORE. It processes array modifications instantly, making complex data retrieval smooth and error-free.

  1. 1. Open your workbook in WPS: Launch WPS Spreadsheet and open the document containing your dataset.
  2. 2. Select the destination cell: Click on the cell where you want to output the lookup result.
  3. 3. Enter the combined formula: Type your XLOOKUP and TEXTBEFORE formula, applying either the text conversion (&"") or number conversion (--) technique.
  4. 4. Calculate the result: Press Enter to instantly fetch and display the matched data.
Fully compatible with Microsoft Excel file formats (.xlsx, .xls) and advanced formulas.Easily handle complex formula combinations like XLOOKUP and TEXTBEFORE.Smooth processing of dynamic arrays without system lag.Free, lightweight, and features a familiar user interface for quick adoption.
microsoft office alternative - wps office

Frequently Asked Questions

Why does XLOOKUP return an #N/A error when using TEXTBEFORE?

XLOOKUP requires an exact match of both value and data type by default. TEXTBEFORE extracts data as a text string, so if you are trying to look it up in a column formatted as numbers, XLOOKUP will not recognize it as a match. You must align the data types by converting the text to a number or the number range to text.

Can I use VLOOKUP instead of XLOOKUP to do this?

Yes, you can use VLOOKUP, but the best approach is to convert the TEXTBEFORE result to a number (using VALUE or --) rather than altering the lookup array. For example: =VLOOKUP(--TEXTBEFORE(E2,"_"), A1:C22, 2, FALSE).

What if the text string contains multiple delimiters?

The TEXTBEFORE function includes an optional 'instance_num' argument. You can add a third argument to specify which delimiter instance to use (e.g., TEXTBEFORE(E2, "_", 2) extracts all text before the second underscore).

Does TEXTAFTER cause the same data type issues?

Yes. TEXTAFTER also returns text values, so if you are extracting numeric characters and using them as a lookup value against a range of numbers, you will encounter the same mismatch error. The same conversion solutions apply.