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.
Written by Allen Wyatt (last updated May 29, 2021)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365
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.
Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!
Reference a cell in a macro, and if that cell is blank Excel normally equates that to a zero value. What if you don't ...
Discover MoreEnter a formula (starting with an equal sign) and you may be surprised if Excel doesn’t calculate the formula. Here's a ...
Discover MoreWhen you enter references to cells in a worksheet, using the Fill Handle to propagate the formulas to other cells can be ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2021-06-09 05:02:45
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
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"
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.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments