Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 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 Microsoft 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

Determining Word Frequency

How to construct a word frequency list.

Discover More

Automatically Changing References to VBA Libraries

VBA libraries are used to provide some functions to your macros. These libraries are often tied to the version of Excel ...

Discover More

Getting the Name of the Worksheet Into a Cell

Excel allows you to change the names assigned to the worksheets in a workbook. If you want to have those names appear in ...

Discover More

Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!

More ExcelTips (ribbon)

Deriving High and Low Non-Zero Values

When analyzing your numeric data, you may need to figure out the largest and smallest numbers in a set of values. If you ...

Discover More

Stopping a Formula from Updating References

Insert or delete a column, and Excel automatically updates references within formulas that are affected by the change. If ...

Discover More

Patterns of Numbers with a Formula

Want to create a sequential pattern using formulas? It's easy to do if you take a look at how your data repeats. This tip ...

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 seven less than 7?

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.