亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Table of Contents
How to compare two cells in Excel
Case-insensitive formula to compare 2 cells
Case-sensitive formula to compare strings in Excel
How to compare multiple cells in Excel
Case-insensitive formula to compare more than 2 cells
Case-sensitive formula to compare text in several cells
Compare a range of cells to a sample cell
Case-insensitive formula to compare cells to a sample text
Case-sensitive formula to compare strings to a sample text
How to compare two cells by string length
Compare two cells by occurrences of a specific character
Practice workbook for download
Home Software Tutorial Office Software Excel: Compare strings in two cells for matches (case-insensitive or exact)

Excel: Compare strings in two cells for matches (case-insensitive or exact)

Apr 16, 2025 am 11:26 AM

The tutorial shows how to compare text strings in Excel for case-insensitive and exact match. You will learn a number of formulas to compare two cells by their values, string length, or the number of occurrences of a specific character, as well as how to compare multiple cells.

When using Excel for data analysis, accuracy is the most vital concern. Incorrect information leads to missed deadlines, misjudged trends, wrong decisions and lost revenues.

While Excel formulas are always perfectly true, their results may be wrong because some flawed data penetrated into the system. In this case, the only remedy is to check data for accuracy. It's no big deal to compare two cells manually, but it's next to impossible to spot the differences between hundreds and thousands of text strings.

This tutorial will teach you how to automate the tedious and error-prone task of cell comparison and what formulas are best to use in each particular case.

How to compare two cells in Excel

There are two different ways to compare strings in Excel depending on whether you seek case-sensitive or case-insensitive comparison.

Case-insensitive formula to compare 2 cells

To compare two cells in Excel ignoring case, use a simple formula like this:

=A1=B1

Where A1 and B1 are the cells you are comparing. The result of the formula are Boolean values TRUE and FALSE.

If you want to output your own texts for matches and differences, embed the above statement in the logical test of the IF function. For example:

=IF(A1=B1, "Equal", "Not equal")

As you see in the screenshot below, both formulas compare text strings, dates and numbers equally well:

Excel: Compare strings in two cells for matches (case-insensitive or exact)

Case-sensitive formula to compare strings in Excel

In some situations, it may be important not only to compare text values of two cells, but also to compare the character case. Case-sensitive text comparison can be done using the Excel EXACT function:

EXACT (text1, text2)

Where text1 and text2 are the two cells you are comparing.

Assuming your strings are in cells A2 and B2, the formula goes as follows:

=EXACT(A2, B2)

As the result, you get TRUE for text strings match exactly including the case of each character, FALSE otherwise.

If you want the EXACT function to deliver some other results, embed it in an IF formula and type your own text for value_if_true and value_if_false arguments:

=IF(EXACT(A2 ,B2), "Exactly equal", "Not equal")

The following screenshot shows the results of the case-sensitive string comparison in Excel:

Excel: Compare strings in two cells for matches (case-insensitive or exact)

How to compare multiple cells in Excel

To compare more than 2 cells in a row, use the formulas discussed in the above examples in combination with the AND operator. The full details follow below.

Case-insensitive formula to compare more than 2 cells

Depending on how you want to display the results, utilize one of the following formulas:

=AND(A2=B2, A2=C2)

or

=IF(AND(A2=B2, A2=C2), "Equal", "Not equal")

The AND formula returns TRUE if all of the cells contain the same value, FALSE if any value is different. The IF formula outputs the labels that you type in it, "Equal" and "Not equal" in this example.

As demonstrated in the screenshot below, the formula works perfectly with any data types - text, dates and numeric values:

Excel: Compare strings in two cells for matches (case-insensitive or exact)

Case-sensitive formula to compare text in several cells

To compare multiple strings to each other to see if they match exactly, use the following formulas:

=AND(EXACT(A2,B2), EXACT(A2, C2))

Or

=IF(AND(EXACT(A2,B2), EXACT(A2, C2)),"Exactly equal", "Not equal")

Like in the previous example, the first formula delivers TRUE and FALSE values, whereas the second one displays your own texts for matches and differences:

Excel: Compare strings in two cells for matches (case-insensitive or exact)

Compare a range of cells to a sample cell

The following examples show how you can verify that all cells in a given range contain the same text as in a sample cell.

Case-insensitive formula to compare cells to a sample text

If the character case does not really matter, you can use the following formula to compare cells to a sample:

ROWS(range)*COLUMNS(range)=COUNTIF(range, sample cell)

In the logical test of the IF function, you compare two numbers:

  • The total number of cells in a specified range (the number of rows multiplied by the number of columns), and
  • The number of cells containing the same value as in the sample cell (returned by the COUNTIF function).

Assuming the sample text is in C2 and the strings to compare are in the range A2:B6, the formula goes as follows:

=ROWS(A2:B6)*COLUMNS(A2:B6)=COUNTIF(A2:B6,C2)

To make the results more user-friendly, i.e. output something like "All match" and "Not all match" instead of TRUE and FALSE, use the IF function like we did in the previous examples:

=IF(ROWS(A2:B6)*COLUMNS(A2:B6)=COUNTIF(A2:B6,C2),"All match", "Not all match")

Excel: Compare strings in two cells for matches (case-insensitive or exact)

As shown the above screenshot, the formula perfectly copes with a range of text strings, but it can also be used to compare numbers and dates.

Case-sensitive formula to compare strings to a sample text

If the character case makes a difference, you can compare strings to the sample text using the following array formulas.

IF(ROWS(range)*COLUMNS(range)=SUM(--EXACT(sample_cell, range)), "text_if_match", "text_if_not match")

With the source range residing in A2:B6 and the sample text in C2, the formula takes the following shape:

=IF(ROWS(A2:B6)*COLUMNS(A2:B6)=SUM(--EXACT(C2, A2:B6)), "All match", "Not all match")

Unlike regular Excel formulas, array formulas are completed by pressing Ctrl Shift Enter. If entered correctly, Excel encloses the array formula in {curly braces}, as shown in the screenshot:

Excel: Compare strings in two cells for matches (case-insensitive or exact)

To identify if a certain value is present or absent in a range, please see Check if a value exists in a range.

How to compare two cells by string length

Sometimes you may want to check if the text strings in each row contain an equal number of characters. The formula for this task is very simple. First, you get the string length of two cells using the LEN function, and then compare the numbers.

Supposing the strings to be compared are in cells A2 and B2, use either of the following formulas:

=LEN(A2)=LEN(B2)

Or

=IF(LEN(A2)=LEN(B2), "Equal", "Not equal")

As you already know, the first formula returns Boolean values TRUE or FALSE, whereas the second formula outputs your own results:

Excel: Compare strings in two cells for matches (case-insensitive or exact)

As demonstrated in the screenshot above, the formulas work for text strings as well as numbers.

Tip. If two seemingly equal strings return different lengths, most likely the problem is in leading or trailing spaces in one or both cells. In this case, remove extra spaces using the TRIM function. The detailed explanation and formula examples can be found here: How to trim spaces in Excel.

Compare two cells by occurrences of a specific character

This is the last example in our Excel Compare Strings tutorial, and it shows a solution for a rather specific task. Supposing, you have 2 columns of text strings that contain a character important to you. Your goal is to check whether two cells in each row contain the same number of occurrences of a given character.

To make things clearer, consider the following example. Let's say, you have two lists of orders shipped (column B) and received (column C). Each row contains orders for a specific item, whose unique identifier is included in all order IDs and is listed in the same row in column A (please see the screenshot below). You want to make sure that each row contains an equal number of shipped and received items with that specific ID.

To solve this problem, write a formula with the following logic.

  • Firstly, replace the unique identifier with nothing using the SUBSTITUTE function:

    SUBSTITUTE(A1, character_to_count,"")

  • Then, calculate how many times the unique identifier appears in each cell. For this, get the string length without the unique identifier and subtract it from the total length of the string. This part shall be written for cell 1 and cell 2 individually, for example:

    LEN(cell 1) - LEN(SUBSTITUTE(cell 1, character_to_count, "")) and LEN(cell 2) - LEN(SUBSTITUTE(cell 2, character_to_count, ""))

  • Lastly, you compare these 2 numbers by placing the equality sign (=) in between the above parts.
LEN(cell 1) - LEN(SUBSTITUTE(cell 1, character_to_count, ""))= LEN(cell 2) - LEN(SUBSTITUTE(cell 2, character_to_count, ""))

In our example, the unique identifier is in A2, and the strings to compare are in cells B2 and C2. So, the complete formula is as follows:

=LEN(B2)-LEN(SUBSTITUTE(B2,$A2,""))=LEN(C2)-LEN(SUBSTITUTE(C2,$A2,""))

The formula returns TRUE if cells B2 and C2 contain an equal number of occurrences of the character in A2, FALSE otherwise. To make the results more meaningful for your users, you can embed the formula in the IF function:

=IF(LEN(B2)-LEN(SUBSTITUTE(B2, $A2,""))=LEN(C2)-LEN(SUBSTITUTE(C2, $A2,"")), "Equal", "Not equal")

Excel: Compare strings in two cells for matches (case-insensitive or exact)

As you can see in the screenshot above, the formula works perfectly despite a couple of additional complications:

  • The character to be counted (unique identifier) can appear anywhere in a text string.
  • The strings contain a variable number of characters and different separators such as semicolon, comma or space.

This is how you compare strings in Excel. To have a closer look at the formulas discussed in this tutorial, you are welcome to download our sample sheet below. I thank you for reading and hope to see you on our blog next week!

Practice workbook for download

Excel - compare strings examples (.xlsx file)

The above is the detailed content of Excel: Compare strings in two cells for matches (case-insensitive or exact). For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1488
72
how to group by month in excel pivot table how to group by month in excel pivot table Jul 11, 2025 am 01:01 AM

Grouping by month in Excel Pivot Table requires you to make sure that the date is formatted correctly, then insert the Pivot Table and add the date field, and finally right-click the group to select "Month" aggregation. If you encounter problems, check whether it is a standard date format and the data range are reasonable, and adjust the number format to correctly display the month.

How to Fix AutoSave in Microsoft 365 How to Fix AutoSave in Microsoft 365 Jul 07, 2025 pm 12:31 PM

Quick Links Check the File's AutoSave Status

how to repeat header rows on every page when printing excel how to repeat header rows on every page when printing excel Jul 09, 2025 am 02:24 AM

To set up the repeating headers per page when Excel prints, use the "Top Title Row" feature. Specific steps: 1. Open the Excel file and click the "Page Layout" tab; 2. Click the "Print Title" button; 3. Select "Top Title Line" in the pop-up window and select the line to be repeated (such as line 1); 4. Click "OK" to complete the settings. Notes include: only visible effects when printing preview or actual printing, avoid selecting too many title lines to affect the display of the text, different worksheets need to be set separately, ExcelOnline does not support this function, requires local version, Mac version operation is similar, but the interface is slightly different.

How to change Outlook to dark theme (mode) and turn it off How to change Outlook to dark theme (mode) and turn it off Jul 12, 2025 am 09:30 AM

The tutorial shows how to toggle light and dark mode in different Outlook applications, and how to keep a white reading pane in black theme. If you frequently work with your email late at night, Outlook dark mode can reduce eye strain and

How to Screenshot on Windows PCs: Windows 10 and 11 How to Screenshot on Windows PCs: Windows 10 and 11 Jul 23, 2025 am 09:24 AM

It's common to want to take a screenshot on a PC. If you're not using a third-party tool, you can do it manually. The most obvious way is to Hit the Prt Sc button/or Print Scrn button (print screen key), which will grab the entire PC screen. You do

Where are Teams meeting recordings saved? Where are Teams meeting recordings saved? Jul 09, 2025 am 01:53 AM

MicrosoftTeamsrecordingsarestoredinthecloud,typicallyinOneDriveorSharePoint.1.Recordingsusuallysavetotheinitiator’sOneDriveina“Recordings”folderunder“Content.”2.Forlargermeetingsorwebinars,filesmaygototheorganizer’sOneDriveoraSharePointsitelinkedtoaT

how to find the second largest value in excel how to find the second largest value in excel Jul 08, 2025 am 01:09 AM

Finding the second largest value in Excel can be implemented by LARGE function. The formula is =LARGE(range,2), where range is the data area; if the maximum value appears repeatedly and all maximum values ??need to be excluded and the second maximum value is found, you can use the array formula =MAX(IF(rangeMAX(range),range)), and the old version of Excel needs to be executed by Ctrl Shift Enter; for users who are not familiar with formulas, you can also manually search by sorting the data in descending order and viewing the second cell, but this method will change the order of the original data. It is recommended to copy the data first and then operate.

how to get data from web in excel how to get data from web in excel Jul 11, 2025 am 01:02 AM

TopulldatafromthewebintoExcelwithoutcoding,usePowerQueryforstructuredHTMLtablesbyenteringtheURLunderData>GetData>FromWebandselectingthedesiredtable;thismethodworksbestforstaticcontent.IfthesiteoffersXMLorJSONfeeds,importthemviaPowerQuerybyenter

See all articles