Excel Formula to Check Whether Text Contains 2020, 2021, or 2022
Question details
Check whether a cell contains any of the text strings 2020, 2021, or 2022 and return y or n.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A worksheet contains text that may include one of several year values.
- Observed behavior
- The desired formula returns y when any listed year appears in the text and n when none appears.
Identify the cell containing the text to check; the examples below use I2. Choose an empty cell for the result and adjust the reference if your text is elsewhere.
Use SEARCH and OR to check for any listed year
Use this compact formula to return y if I2 contains 2020, 2021, or 2022.
SEARCH looks for each year string in I2. ISNUMBER converts successful matches to TRUE, and OR checks whether at least one match was found.
Select an empty cell, such as J2, and enter =IF(OR(ISNUMBER(SEARCH({"2020","2021","2022"},I2))),"y","n").
Press Enter. The cell returns y if any listed string appears in I2; otherwise, it returns n.
Drag the fill handle from J2 down the column to check the corresponding cells in column I.
Check each year separately for broader Excel compatibility
Use separate SEARCH tests if you prefer a formula without an array constant.
Find Multiple Years in Text with WPS Spreadsheet
Use SEARCH, ISNUMBER, OR, and IF in WPS Spreadsheet to check a text cell for the listed years and return y or n.
- 1. Open your worksheet: Open WPS Spreadsheet and use Open to select your Excel workbook.
- 2. Select a result cell: Click an empty cell, such as J2, next to the text in I2.
- 3. Enter the formula: Enter =IF(OR(ISNUMBER(SEARCH("2020",I2)),ISNUMBER(SEARCH("2021",I2)),ISNUMBER(SEARCH("2022",I2))),"y","n") and press Enter.
- 4. Copy the formula: Drag the cell's fill handle down to check additional rows.

Frequently Asked Questions
How can I make the text search case-sensitive?
Replace SEARCH with FIND in the formula. FIND distinguishes uppercase from lowercase, although case makes no difference when searching for digits alone.
Why does SEARCH return an error when a year is missing?
SEARCH returns a #VALUE! error when it cannot find the specified text. Wrapping it in ISNUMBER converts that result to FALSE so OR can test the other years.
Can I return Yes or No instead of y or n?
Yes. Replace the last two arguments of IF with "Yes" and "No", for example: =IF(OR(ISNUMBER(SEARCH({"2020","2021","2022"},I2))),"Yes","No").
Will the formula match a year inside a longer number?
Yes. SEARCH looks for the specified characters anywhere in the cell, so 2020 also matches within a longer string such as 20201.
What if the compact formula does not work in my version of Excel?
In older versions, try confirming the array formula with Ctrl+Shift+Enter. Alternatively, use the separate SEARCH tests shown in the second solution and press Enter normally.




