How to Extract Excel Rows Beginning with Specific Text (CD or US)
Question details
The user wants to extract specific rows from an Excel dataset that begin with the letters "CD" or "US" without altering the original order of the data.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Filtering a dataset based on the starting characters of a text string while preserving the original source sequence for reporting or analysis.
- Observed behavior
- The goal is to obtain a dynamic list of matching rows in their original sequence, ideally using a formula that can be easily copied or pasted as values.
Ensure your dataset is organized in a clear column structure and that you are using a version of Excel or WPS Spreadsheet that supports dynamic array functions like FILTER.
Use the FILTER and LEFT Functions
This is the most efficient method to dynamically extract rows starting with specific text strings while maintaining the exact original order.
By combining Excel's FILTER function with the LEFT function, you can evaluate the first few characters of each cell in a range. Using the plus (+) operator allows you to apply an 'OR' logic condition, successfully pulling rows that start with either of your targeted strings.
Click on the empty destination cell where you want the extracted data to begin.
Type the formula: =FILTER(A2:A22,(LEFT(A2:A22,2)="CD")+(LEFT(A2:A22,2)="US")) into the formula bar.
Modify the range "A2:A22" within the formula to match the actual location and size of your dataset.
Press Enter to execute the formula. The matching rows will automatically spill into the cells below in their original sequence.

Use a Helper Column and Standard Sorting
A manual alternative for older software versions that do not support dynamic array formulas like FILTER.
Extract and Filter Data Effortlessly with WPS Spreadsheet
WPS Office provides robust support for advanced dynamic array functions, making complex data extraction tasks simple and efficient without modifying your original files.
- 1. Open Your File: Launch WPS Spreadsheet and open the document containing your dataset.
- 2. Select Destination: Click on a blank cell where you want the filtered rows to be extracted.
- 3. Apply Formula: Input the dynamic formula =FILTER(A2:A22,(LEFT(A2:A22,2)="CD")+(LEFT(A2:A22,2)="US")) and adjust ranges as needed.
- 4. View Results: Press Enter to instantly display your extracted rows while preserving the original dataset's exact order.

Frequently Asked Questions
Can I extract rows based on more than two text conditions?
Yes, you can add more conditions to the FILTER formula by adding additional logical statements within parentheses, linked by the plus (+) sign, such as +(LEFT(A2:A22,2)="UK").
Why is my FILTER formula returning a #CALC! error?
The #CALC! error typically occurs when the FILTER function finds no rows that match your specific criteria. You can add an optional 'if_empty' argument to the formula, like =FILTER(range, criteria, "No matches"), to handle this gracefully.
Does this formula work in older versions of Excel?
The FILTER function is a dynamic array formula available in Microsoft 365, Excel 2021, and modern suites like WPS Office. If you are using an older version, you will need to use the Helper Column sorting method or a combination of the INDEX and MATCH functions.
How do I extract rows based on the end of a string instead of the beginning?
To extract rows based on the ending characters, replace the LEFT function with the RIGHT function in your formula. For example: =FILTER(A2:A22,(RIGHT(A2:A22,2)="CD")).




