Counting Product Codes with Case Sensitivity in Excel

VBA・Officeカテゴリを表すパンダのイラスト VBA / Office

About This Article
This article was created using an automated generation workflow utilizing generative AI. We verified the function specifications in Microsoft Support and created a practice scenario comparing counts using a sample product ledger.

Verification Status: 📘 Official Information Confirmed – Excel Physical Device Unverified

Supported Environments, Capabilities, and Limitations (Official Information Confirmed: November 26, 2026)

ItemCondition
TargetExcel for Microsoft 365, Excel 2024/2021/2019/2016 (Listed in official documentation for each function)
OperationEnter text strings and formulas into worksheet cells
Use CaseAggregate the count of product codes from a list that match strictly, including case sensitivity
License & PermissionsAn environment capable of running Excel and an editable practice workbook. Copilot, macros, and external connections are not required
LimitationsVisual appearance and formatting of characters are not compared. Input errors and differences in code structures must be checked separately
UnverifiedActual formula calculation and display across various Excel environments

When product codes AB-12 and ab-12 are managed as separate products, using COUNTIF to count the items will sum both. If you need a count that matches even the case, you can use EXACT to determine matches row by row and SUMPRODUCT to sum those results. Instead of a one-to-one string comparison, this section covers how to obtain an exact count from multiple rows and even verify the breakdown of the aggregated results.

First, create a product inventory of 4 rows

In a new workbook, enter Product Code in A1 and Inventory in B1. Enter the following values into A2:B5. These are fictitious data for understanding the calculation rather than real products.

RowColumn A: Product CodeColumn B: Inventory
2AB-1210
3ab-1220
4AB-1230
5AB-1340

Enter Search Code in D1 and AB-12 in D2. Enter Standard Count in E1 and Case-Sensitive Count in F1, and then enter =COUNTIF(A2:A5,D2) in E2 and =SUMPRODUCT(--EXACT(A2:A5,D2))Enter

Value of D2Expected value of E2Expected value of F2
AB-1232
ab-1231
AB-1311
XY-9900

The numerical values here are expected values calculated from official specifications and dummy data, not actual measured Excel values. If only D2 is changed to ab-12, E2 is expected to remain unchanged, and F2 is expected to change from 2 to 1. Since neither the aggregation range nor the product master has been modified, you can verify that the difference in the results stems from the comparison conditions.

Making TRUE and FALSE values summable

EXACT is a function that compares strings. Matching rows return TRUE, and mismatched rows return FALSE. However, what we want to know is not the evaluation of each row, but the total number of matching rows. Therefore, the evaluation results are converted into numeric values 1 and 0 before being summed.

Change D2 back to AB-12 and enter match evaluation in C1. In C2, enter =EXACT(A2,$D$2) and copy it down to C5. The lookup cell D2 is fixed using dollar signs. When copied, A2 changes to A3 and A4, but the lookup target remains D2 throughout.

RowExpected EXACT ResultNumeric Value
2TRUE1
3FALSE0
4TRUE1
5FALSE0

In the formula in F2, EXACT returns this evaluation as an array, and the leading double minus signs handle the conversion to numbers. The first sign reversal turns TRUE into -1 and FALSE into 0, and the second reversal turns them into 1 and 0. When a single array is passed to SUMPRODUCT, the result is the sum of those numbers. Since it is the sum of 1, 0, 1, and 0, the result is 2 items.

The double minus is not a special aggregation function. It is a syntax used to convert boolean evaluations into numbers. Rather than copying a long formula without understanding how it works, checking each row's evaluation in column C first and then combining them into a single formula makes it easier to explain the reasons for discrepancies in your work.Official EXACT DocumentationandSee also the official SUMPRODUCT documentation.Please refer to this as well.

Do not confuse the number of rows with the total inventory count.

The value 2 calculated so far represents the number of rows where the product code matches. It does not mean there are 2 items in inventory. In a ledger where the same product appears in multiple rows across different warehouses, the number of matching rows and the actual inventory quantity are distinct aggregated values.

Type case-sensitive inventory count in G1, and enter =SUMPRODUCT(--EXACT(A2:A5,D2),B2:B5) in G2. This formula multiplies the match indicators 1 and 0 by the inventory quantity of each row before summing them up. If D2 is AB-12, only 10 and 30 are targeted resulting in 40, and if it is ab-12, it is expected to be 20.

The formula for checking the count determines how many matching rows exist. The formula for the inventory count adds the quantities held in those rows. For example, if the same code is found in two warehouses and the count is 2 while the inventory quantity is 40, the person in charge checks the two storage locations and reconciles the quantities. It is important to choose the formula depending on which value needs to be reported.

Ensure column B uses uniform numeric data. If quantities are stored as text, the expected sum may not be achieved. If the source data contains calculation errors, the aggregation formula may also result in an error. Align the reference ranges for columns A and B to the same number of rows.

Distinguish between empty cells and trailing spaces.

In operational summary sheets, formulas may remain even when the search field is blank. If you do not want to aggregate empty codes while the field is blank, change F2 to =IF(D2="","",SUMPRODUCT(--EXACT(A2:A5,D2))). If there are no characters in the search cell, the result field is left blank, and the count is displayed only when a code is entered.

This design allows you to distinguish between an unentered state and zero search results. An empty string display indicates that search criteria are not set, while a numeric 0 indicates that a search was performed but no matching targets were found. When passing aggregation results to subsequent formulas, ensure you do not treat empty strings and 0 as the same.

Even if the case matches, adding a single half-width space at the end makes it a different string. For example, if you change A4 to ="AB-12"&" ", and D2 is AB-12, F2 is expected to change from 2 to 1. If visual distinction is difficult, compare character lengths using LEN or inspect rows where mismatches occur in column C. However, if whitespace is an official part of the code, do not delete it arbitrarily. Verify input rules and the original document before making corrections.

Troubleshooting mismatches

SymptomPoints to check
Count is higher than expectedCheck if COUNTIF is counting cases as identical regardless of letter case
Rows that should match are not being countedColumn C judgment, blank, entered string
Copying yields a different resultFixed reference for search cell and aggregation range
Errors such as #VALUE!Source data errors or mismatched array row counts
Total quantity is smallIs the value in column B entered as a number?
Calculation is slowIs the range restricted to the necessary number of rows?

Converting all errors to 0 from the start makes it impossible to distinguish between correct zero counts and calculation failures. First, check the source data and intermediate judgments. Microsoft's documentation on SUMPRODUCT also warns about the computational load of referencing entire columns. As ledgers grow larger, limit the range to the portion containing data and review the number of repeatedly calculated formulas.

Application to business practice: Aligning aggregation rules with details

Whether product codes are case-sensitive is determined by the specifications of the product master, not by Excel's features. Using strict comparison on a case-insensitive master will treat correctly registered products as different items. Conversely, aggregating a case-sensitive master using only COUNTIF risks combining different products into one.

If the aggregation results differ, first keep the original code strings, display the standard count and case-sensitive count side by side, and check for discrepancies. Clearly document the definitions of counts and total quantities for anyone who modifies the search criteria. Process the batch capitalization of original codes as a separate task after verifying the code structure.

ExistingMicrosoft's COUNTIF documentationWith reference to , choose the comparison method according to the application. It is logical to use COUNTIF where standard aggregation is sufficient, and EXACT for aggregating identifiers that require case sensitivity. You do not always need to use both formulas.

Summary

For list aggregation with case sensitivity, evaluate each row using EXACT, convert the results to 1s and 0s using a double unary, and sum them with SUMPRODUCT. Creating an intermediate evaluation column allows you to verify the correspondence between counts and details. Handling counts, total quantities, blanks, and data errors separately is key when utilizing summary tables in business operations.

Official Information and Primary Sources

Official information verified on November 26, 2026. Calculations in a live Excel environment and behavior with actual product ledgers have not been verified.

Document information

Article title
Counting Product Codes with Case Sensitivity in Excel
Published
Updated
Source
https://papanda925.com/?p=18781&lang=en

License: Text and original figures for which this site holds the relevant rights are available under CC BY 4.0 , unless otherwise noted. This article may include content created or edited with generative AI. If code has a separate license notice or a linked GitHub repository license, that license takes precedence for the code. Quotations, third-party materials, images, and trademarks are excluded from this license. Usage policy

Copied title and URL