Skip to content
Free Excel Tutorials
  • Home
  • Excel For Beginners
  • Excel Intermediate
  • Advanced Excel For Experts

Data Analysis

  • How to Use Solver Tool in Excel
  • How To Load Analysis ToolPak in Excel
  • Move chart to a separate worksheet in Excel
  • Error Bars in Excel
  • Filter Data Based on Date in Excel

References

  • Lookup entire row in Excel
  • Extract all partial matches in Excel
  • How to use Excel ROW Function
  • Two-column Lookup in Excel
  • How to use Excel COLUMN Function

Data Validations

  • Excel Data validation unique values only
  • Excel Data validation date in specific year
  • Excel Data validation must contain specific text
  • Excel Data validation number multiple 100
  • Prevent invalid data entering in specific cells

if cell contains this or that in Excel

by

This tutorial shows how to calculate if cell contains this or that in Excel using the example below;

Formula

=IF(SUM(COUNTIF(B5,{"*text1*","*text2*"})),"x","")

Explanation

To check to see if a cell contains more than one substring, you can use a formula based on the COUNTIF function.

In the example shown, the formula in C5 is:

=IF(SUM(COUNTIF(B5,{"*abc*","*aaa*"})),"x","")

How this formula works

The core of this formula is COUNTIF, which returns zero if none of the substrings is found, and a positive number if at least one substring is found. The twist in this case is that we are giving COUNTIF more than one substring to look for in the criteria, supplied as an “array constant”.  As a result, COUNTIF will return an array of results, with one result per item in the original criteria.

Worked Example:   One way to track attendance using Excel formula

Note that we are also using the asterisk (*) as a wildcard for zero or more characters on either side of the substrings. This is what allows COUNTIF to count the substrings anywhere in the text (i.e. this provides the “contains” behavior).

Worked Example:   If cell begins with x, y, or z in Excel

Because we are getting back an array from COUNTIF, we use the SUM function to sum all items in the array. The result goes into the IF function as the “logical test”.  Any positive number will be evaluated as TRUE, so you can supply any values you like for value if true and value if false.

Post navigation

Previous Post:

VLOOKUP without #N/A error in Excel

Next Post:

How to Create Gantt Chart in Excel

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Learn Basic Excel

Ribbon
Workbook
Worksheets
Format Cells
Find & Select
Sort & Filter
Templates
Print
Share
Protect
Keyboard Shortcuts

Categories

  • Charts
  • Data Analysis
  • Data Validation
  • Excel Functions
    • Cube Functions
    • Database Functions
    • Date and Time Functions
    • Engineering Functions
    • Financial Functions
    • Information Functions
    • Logical Functions
    • Lookup and Reference Functions
    • Math and Trig Functions
    • Statistical Functions
    • Text Functions
    • Web Functions
  • Excel VBA
  • Excel Video Tutorials
  • Formatting
  • Grouping
  • Others

Logical Functions

  • TRUE function: Description, Usage, Syntax, Examples and Explanation
  • How to use IFS function in Excel
  • OR function Examples in Excel
  • XOR function: Description, Usage, Syntax, Examples and Explanation
  • Not Equal To ‘<>‘ operator in Excel

Date Time

  • How to calculate nth day of week in month in Excel
  • How to calculate next anniversary date or birthday in Excel
  • Calculate number of hours between two times in Excel
  • Convert decimal minutes to Excel time
  • Add months to date in Excel

Grouping

  • Map text to numbers in Excel
  • Group arbitrary text values in Excel
  • Group times into 3 hour buckets in Excel
  • How to randomly assign people to groups in Excel
  • If cell contains one of many things in Excel

General

  • Check if range contains a value not in another range in Excel
  • Using Existing Templates in Excel
  • How to get original number from percent change in Excel
  • Check if multiple cells have same value in Excel
  • Select, Insert, Rename, Move, Delete Worksheets in Excel
© 2023 xlsoffice . All Right Reserved. | Teal Smiles | Abbreviations And Their Meaning