Excel Function Contains

The CONTAINS function in Excel is a powerful tool that allows you to check if a specific value or text is present within a given range or cell. This function is particularly useful when you need to search for specific keywords, phrases, or patterns within your data. In this blog post, we will explore the CONTAINS function, its syntax, and various practical examples to help you understand its versatility and applications.

Understanding the CONTAINS Function

The CONTAINS function in Excel is a built-in function that returns a logical value (TRUE or FALSE) based on whether the specified text is found within a given range or cell. It is a case-insensitive function, meaning it does not differentiate between uppercase and lowercase letters.

The basic syntax of the CONTAINS function is as follows:

CONTAINS(range, value)
  • range: This is the range of cells or a single cell reference that you want to search within.
  • value: The value or text that you are looking for within the specified range.

The function returns TRUE if the specified value is found within the range, and FALSE otherwise.

Examples and Use Cases

Checking for Specific Keywords

One common use of the CONTAINS function is to check for the presence of specific keywords or phrases within a dataset. For example, let's say you have a list of product names, and you want to identify all the products that contain the word "blue" in their names.

Product Name Contains "Blue"?
Blueberry Jam TRUE
Red Strawberries FALSE
Blue Sky Yogurt TRUE
Green Tea FALSE

You can use the CONTAINS function to achieve this. In this case, the formula would be:

=CONTAINS(A2:"Blue")

Where A2 is the range containing the product names, and "Blue" is the keyword we are searching for.

Identifying Email Addresses

The CONTAINS function can also be used to identify email addresses within a list of contacts. For example, you might have a dataset with various contact information, and you want to filter out only the rows that contain valid email addresses.

Name Email
John Doe john.doe@example.com
Jane Smith janesmith
Robert Johnson robert@gmail.com
Emily Brown emilyb@yahoo.co.uk

To identify valid email addresses, you can use a formula like this:

=CONTAINS(B2,"@")

Here, B2 is the range containing the email addresses, and "@" is the character we are searching for to identify email addresses.

Extracting Data Based on Patterns

The CONTAINS function is not limited to simple keyword searches. You can also use it to extract data based on specific patterns or criteria. For instance, you might have a list of URLs, and you want to extract only the URLs that contain the word "blog" in their domain.

URL Contains "Blog"?
https://www.example.com/blog/post1 TRUE
https://www.anotherexample.com/news FALSE
https://www.myblog.net/articles TRUE
https://www.yetanother.org/info FALSE

The formula for this scenario would be:

=CONTAINS(A2,"blog")

Where A2 is the range containing the URLs, and "blog" is the pattern we are looking for.

Tips and Notes

🌟 Note: The CONTAINS function is case-insensitive, so it will match "Blue" and "blue" as the same value.

🔍 Note: You can use wildcards such as * and ? in the value argument to perform more complex searches. For example, "*blue*" will match any text containing the word "blue" anywhere within the cell.

⚠️ Note: The CONTAINS function does not support regular expressions. If you need more advanced pattern matching, you can consider using the FIND or SEARCH functions in combination with other formulas.

Conclusion

The CONTAINS function in Excel is a versatile tool that can greatly enhance your data analysis and filtering capabilities. By understanding its syntax and various use cases, you can efficiently search for specific values, keywords, or patterns within your Excel sheets. Whether you're working with product names, email addresses, or URLs, the CONTAINS function can help you extract and organize data with ease.

Frequently Asked Questions

Can I use the CONTAINS function to search for multiple keywords at once?

+

Yes, you can combine the CONTAINS function with the OR or AND functions to search for multiple keywords. For example, =AND(CONTAINS(A2,“blue”),CONTAINS(A2,“green”)) will return TRUE if the cell contains both “blue” and “green.”

Is the CONTAINS function case-sensitive?

+

No, the CONTAINS function is case-insensitive, meaning it treats uppercase and lowercase letters as the same.

Can I use the CONTAINS function to search for numbers within a range of cells?

+

Yes, the CONTAINS function can be used to search for numbers as well. Simply provide the number as the value argument, and it will search for that specific number within the range.

How can I apply the CONTAINS function to multiple cells simultaneously?

+

You can use the CONTAINS function with the IF function to apply it to multiple cells. For example, =IF(CONTAINS(A2,“blue”),“Found”,“Not Found”) will return “Found” if the cell contains “blue” and “Not Found” otherwise.