How to Fix INDEX MATCH Errors with Trailing Spaces in Excel
Question details
The user needs to resolve INDEX and MATCH lookup errors caused by invisible trailing spaces in the source data and requires a reliable method to count rows in dynamic tables.

- Product
- Excel / WPS Spreadsheet
- Device & OS
- not provided
- Scenario
- Looking up data across tables where source text contains hidden formatting like trailing spaces, and referencing dynamic data ranges of unknown lengths.
- Observed behavior
- INDEX MATCH formulas return lookup errors (such as #N/A) due to mismatched text containing hidden spaces, and dynamically changing tables lack explicit row counts for formula referencing.
Before modifying your formulas, ensure your spreadsheet calculation options are set to 'Automatic'. It is also helpful to temporarily click inside the formula bar for a problematic cell to visually inspect for any obvious hidden spaces at the end of your lookup text.
Use Wildcards in the MATCH Formula
Append an asterisk wildcard to the lookup value to ignore trailing spaces and safely match the beginning characters.
If trimming the destination value doesn't work because the hidden spaces are located in the source data, using a wildcard is the most efficient workaround. The asterisk (*) wildcard instructs the MATCH function to find any value that starts with your lookup text, ignoring anything that follows it, including spaces.
Select the cell containing your existing INDEX MATCH formula and click into the formula bar.
Modify the lookup_value argument in the MATCH function by appending &"*" to the end of your cell reference. For example, change MATCH($A2, range, 0) to MATCH($A2&"*", range, 0).
Press Enter to apply the formula. The INDEX MATCH combination should now successfully return the matching value despite any trailing spaces.

Clean Source Data Using the TRIM Function
Remove extra spaces from your source data directly so standard formulas work correctly without wildcards.
Determine Dynamic Row Counts using COUNTA or COUNTIF
Calculate the exact number of rows in a dynamic dataset to prevent formulas from referencing unnecessary blank cells.
Fix Lookup Errors and Manage Dynamic Data Seamlessly in WPS Spreadsheet
WPS Spreadsheet provides a robust formula engine that handles complex INDEX MATCH combinations, wildcards, and dynamic ranges effortlessly. By using WPS, you can quickly implement data cleaning formulas or wildcard lookups to resolve #N/A errors caused by hidden formatting.
- 1. Open your workbook: Launch WPS Spreadsheet and open the file containing your broken lookup formulas.
- 2. Apply wildcards to your formula: Double-click the formula cell and append &"*" to your MATCH lookup value to bypass trailing spaces.
- 3. Clean data efficiently: Use the built-in TRIM function or text-to-columns utilities to permanently strip invisible characters from your source data.
- 4. Build dynamic references: Leverage COUNTA or COUNTIF to accurately define table boundaries and ensure formulas always reference the correct dataset size.

Frequently Asked Questions
Why does INDEX MATCH return #N/A when the text looks exactly the same?
This usually occurs because of hidden trailing or leading spaces, non-breaking spaces (common in exported web data), or minor formatting mismatches. Using wildcards or the TRIM function can resolve these discrepancies.
Can I use wildcards with VLOOKUP the same way as MATCH?
Yes. Just like the MATCH function, you can append &"*" to your lookup value in a VLOOKUP formula (e.g., =VLOOKUP(A2&"*", range, 2, FALSE)) to ignore trailing characters.
What is the difference between COUNTA and COUNTIF when counting rows?
COUNTA counts all cells that are not completely empty, which includes hidden spaces or formulas returning empty strings (""). COUNTIF with a criteria like "> " ensures you are only counting cells that contain visible text or numbers.
Will appending an asterisk wildcard affect exact matches?
Appending an asterisk converts the search into a 'starts with' lookup. While it solves trailing space issues, be cautious if your data contains values where one is a direct prefix of another (e.g., matching 'WS080' might accidentally match 'WS080A').




