Comparing Two Strings (Text)
Comparing Two Strings (Text)
In Excel, you can compare two strings using different methods:
Comparing Two Strings (Text)
- Case Insensitive
- Case Sensitive
In this tutorial, we will learn how to write formulas for both methods.
Comparing Two Strings with Non-Case Sensitive Match:
- Begin by entering an equals sign (=) in a cell.
- Refer to the cell containing the first value.
- Enter another equals sign (=).
- Refer to the cell containing the second value.
- Press Enter to obtain the result.
In the example above, the first cell contains “Excel” and the second cell contains “EXCEL”. Both values are the same, except for the case difference. The result is TRUE because this formula does not consider the case of the text when comparing.
Example Formula: =text1 = text2
Comparing Two Strings with Case Sensitive Match: If you want to consider the case of the text when matching, you can use the EXACT function.
- Enter the EXACT function in a cell.
- Refer to the cell containing the first value.
- Type a comma (,).
- Refer to the cell containing the second value.
- Close the function and press Enter to obtain the result.
In the example above, all the cells contain the same values, but the result is TRUE only where the values match exactly, including the case.
Example Formula: =EXACT(A2,B2)
Using IF to Compare Two Texts: You can also combine the IF function with the methods discussed above.
- Example Formula: =IF(A1=B1,”Yes”,”No”)
- Example Formula: =IF(EXACT(A2,B2),”Yes”,”No”)
By using the IF function, you can specify custom outputs such as “Yes” or “No” based on the comparison result.