Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Office 365. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Ignoring Case in a Comparison.

Ignoring Case in a Comparison

by Allen Wyatt
(last updated May 29, 2021)

8

If you use Excel's IF function to compare two cells that contain text, Excel, by default, ignores the case of the text being compared. For instance, if cell B3 contains "Case" and cell B4 contains "case", then the following formula returns "Match".

=IF(B3=B4,"Match","No Match")

There is no way to modify this behavior using any settings in Excel. If you do not get these results, it is likely because of some other reason. For example, the text in the cells may look the same, but it may not really be the same. For instance, one cell could contain "Case " (with the trailing space), and the other contain "case". In this instance, the formula would return "No Match", and you would assume it is because of the capitalized C in one of the cells, but the real reason is because of the trailing space. You can confirm this by changing the formula, as follows:

=IF(TRIM(B3)=TRIM(B4),"Match","No Match")

The only difference here, of course, is that the TRIM function is used to return a cell value that has all leading and trailing spaces removed.

If you want Excel to actually take text case into account, you should use the EXACT statement, as shown here:

=IF(EXACT(B3,B4),"Match","No Match")

The EXACT function returns True if the cells are exactly the same, otherwise it returns False.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (11118) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Office 365. You can find a version of this tip for the older menu interface of Excel here: Ignoring Case in a Comparison.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Using a Custom Format to Add Dashes

Want some dashes automatically added in values you display in a cell? It may be trickier to develop a custom format than ...

Discover More

Conditionally Formatting Cells Containing Dates

Need to know if a particular cell contains a date value? Excel doesn't have a worksheet function to determine this ...

Discover More

Converting Strings to Numbers

When working with data in a macro, there are two broad categories you can manipulate: numbers and text. Sometimes you ...

Discover More

Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!

More ExcelTips (ribbon)

Identifying Missing Numbers in a Consecutive Series

If you have a series of consecutive numbers in a column, you may want to know if it really is consecutive. (In other ...

Discover More

Checking for Duplicate Rows Based on a Range of Columns

When working with data in Excel, you might want to figure out which rows of data represent duplicates of other rows. If ...

Discover More

Determining Winners, by Category

Do you need to determine the top three values in a range of columns? The techniques discussed in this tip will come in ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 8 + 2?

2021-06-09 05:02:45

Alan Elston

John ,
Your question is a bit off topic / out of place here, -
... - you might find some info on that date stuff here: …
…. https://eileenslounge.com/viewtopic.php?p=267317#p267317 …..
…. https://eileenslounge.com/viewtopic.php?p=267432#p267432 ….
….. https://eileenslounge.com/viewtopic.php?f=27&t=34444 …..

…. Alan Elston


2021-06-08 20:18:48

John Rogers

Hi Allen,
Thankyou for sending me your wonderful EscelTips - they are so very helpful.
I am writing to request for help with a problem I've been having for a while: that of selecting the default format for the date. In Open Office Calc (which mimics Excel) the date defaults to the US format. I prefer the Australian format - dd/mm/yy and whereas I know how to select this for individual cells - I would like to know how to do it as a default setting.
Thankyou
sincerely,

John Rogers


2021-05-31 02:09:43

Alan Elston

Hi Willy, Hi J Woolley
I feel your pain, J. Woolley! …. But I think it’s a general characteristic of almost all Blog site, Forum and most Message Editor windows - this annoying “eating of spaces more than one space”.
No one’s been able to explain to me why it’s done. I can’t see that with modern computers that any saving of memory space can justify the annoyance it often causes. Possibly what Willy said in his first comment explains what’s going on. I must think about tha, I don't really understand so much about HTML stuff.
( I will be taking ownership of one of the Excel Forums at the end of this year, and one thing I hope to do is remove this annoying characteristic, if its possible.
_.... but maybe I don’t need to ….. )
That sounds like a very interesting thing to experiment with , Willy.
That is something completely new that I never tried before.. Thanks for that great tip

I must go and investigate that in a few places.

If I have anything useful to add I will post back here…. I expect it is one of those annoying things like carriage returns where you get different and seemingly inconsistent results in different systems. It probably needs some thorough investigations to track down and control consistently…

Alan Elston


2021-05-30 10:36:15

J. Woolley

@Willy
Sometimes that works for me if I prepare the comment in Notepad using Alt+0160 for non-breaking (hard) spaces, then copy and paste the comment for posting on this site. I'll try it here with my previous examples:
Excel's TRIM("    Now    is    the    time    ") yields "Now is the time"
VBA's Trim("    Now    is    the    time    ") yields "Now    is    the    time"


2021-05-30 05:31:39

Willy Vanhaelen

@J. Woolley
Oops ! doesn't work any more :-)


2021-05-30 05:29:42

Willy Vanhaelen

@J. Woolley
HTML renders only one space even if there are many. You can avoid this by using hard spaces. Hold down the left Alt and type 0160 (or 255) on the numeric key pad. For instance " " are 4 hard spaces.


2021-05-29 10:29:23

J. Woolley

Posting comments on this site is frustrating. I guess Allen uses the TRIM function because he removed "all spaces from text except for single spaces between words" in my previous comment (below). Please ignore those examples.


2021-05-29 10:23:46

J. Woolley

Re. Excel's TRIM function described above, it actually "Removes all spaces from text except for single spaces between words."
TRIM(" Now is the time ") yields "Now is the time"

However, VBA's Trim function returns a "value that has all leading and trailing spaces removed."
Trim(" Now is the time ") yields "Now is the time"


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.