Count the number of cells in an Excel range using multiple criteria with wildcards

Abstract: Count cells in an Excel range using multiple criteria with wildcards via the COUNTIFS function.

Created: 2026-09-02 by

You can count cells in an Excel range using multiple criteria with wildcards by combining the COUNTIFS function with asterisks (*) and question marks (?). The asterisk matches any sequence of characters, while the question mark matches a single character. This approach allows you to perform partial text matching across multiple columns efficiently.

Understanding Wildcard Characters in Excel

Wildcards are special characters that represent other characters when searching for data. In Excel, two primary wildcards are used within functions like COUNTIF and COUNTIFS. Understanding how these work is essential for constructing accurate formulas.

The asterisk (*) represents zero or more characters. For example, the pattern *app* will match "apple", "pineapple", "app", and "application". It is useful when you want to find any cell containing a specific substring regardless of what surrounds it. This is particularly helpful when dealing with messy data where prefixes or suffixes vary significantly.

The question mark (?) represents exactly one character. If you use the pattern ?at, it will match "cat" and "bat" but not "chat" because "chat" has two leading characters. This is valuable when you need to enforce a specific length or structure, such as counting items that start with a specific letter followed by exactly three digits.

It is important to note that if you need to search for an actual asterisk or question mark character rather than using them as wildcards, you must precede them with a tilde (~). For instance, ~* searches for a literal asterisk. However, in most counting scenarios involving product codes or names, you will primarily use the standard asterisk and question mark without the tilde.

Using COUNTIFS with Multiple Criteria

When you need to apply more than one condition, the COUNTIFS function is the appropriate tool. Unlike COUNTIF, which handles only a single criterion, COUNTIFS allows you to specify multiple ranges and corresponding criteria. All criteria must be met simultaneously (logical AND) for a cell to be counted.

The syntax for COUNTIFS is =COUNTIFS(criteria_range1, criteria1, [criteria_range2, criteria2], ...). Each pair consists of the range of cells to evaluate and the condition to apply. When incorporating wildcards, the criteria argument must be enclosed in double quotes or referenced from a cell containing the wildcard string.

For example, suppose you have a list of products in column A and their categories in column B. You want to count how many products are in the "Electronics" category and whose name starts with "Laptop". The formula would look like this:

=COUNTIFS(B:B, "Electronics", A:A, "Laptop*")

In this case, B:B is the range for categories, and "Electronics" is the exact match criterion. A:A is the range for product names, and "Laptop*" is the wildcard criterion that matches any text starting with "Laptop". This combination ensures that only rows satisfying both conditions contribute to the final count.

Step-by-Step Implementation Guide

To implement this effectively in your spreadsheet, follow these structured steps. This method ensures accuracy and makes the formula easy to maintain and debug.

  • Define Your Data Structure: Ensure your data is organized in clear columns. Identify which columns contain the text you need to check against specific patterns.
  • Determine Your Criteria: Decide which parts of the text are fixed and which parts should be flexible. Use asterisks for variable endings or beginnings, and question marks for single-character variability.
  • Construct the Formula: Start with =COUNTIFS(. Add the first range and its criterion. Separate each pair with a comma. Remember to wrap wildcard strings in double quotes if typing them directly into the formula.
  • Reference Cells for Flexibility: Instead of hardcoding criteria, consider placing your search terms in separate cells. For example, if cell D1 contains *phone, you can reference it as =COUNTIFS(A:A, D1). This allows users to change the search term without editing the formula itself.
  • Verify Results: Manually check a few entries to ensure the formula is capturing the intended data. Adjust wildcards if you are getting too many or too few results.

This technique is highly effective for large datasets where manual filtering is impractical. It provides a dynamic way to summarize data based on partial text matches. For related techniques, you might also explore how to handle date-based conditions, as seen in Conditionally counting the total number of matching rows for different dates, or how to count across different sheets as detailed in Count if another sheet - How to Use the COUNTIF Function in Microsoft Excel.

Common Pitfalls and Troubleshooting

While powerful, this method has some common pitfalls. One frequent error is forgetting to enclose wildcard strings in double quotes when typing them directly into the formula bar. Without quotes, Excel may interpret the asterisk as a logical operator or cause a syntax error.

Another issue arises when trying to combine OR logic. COUNTIFS inherently uses AND logic. If you need to count items that match either "Starts with A" OR "Ends with B", you cannot do this in a single COUNTIFS call. Instead, you would need to sum two separate COUNTIFS formulas or use SUMPRODUCT with array constants. For more complex filter logic, refer to Counting the Number of Rows in a Table that Pass a Filter with AND and OR Logic in Excel.

Additionally, be aware that wildcards do not work with numeric data types unless the numbers are stored as text. If your range contains mixed data types, Excel may ignore non-text values when applying text-based wildcards. Always ensure your data format aligns with your search criteria.

Frequently Asked Questions

Can I use wildcards with the SUMIF function?

Yes, you can use wildcards with SUMIF just as you do with COUNTIF. The syntax remains similar, allowing you to sum values in a range based on partial text matches in another range. This is useful for totaling sales figures for products with specific naming patterns.

How do I search for a literal asterisk character?

To search for an actual asterisk instead of using it as a wildcard, you must precede it with a tilde (~). For example, use ~* in your criteria string. This tells Excel to treat the asterisk as a regular character rather than a placeholder for other characters.

Does COUNTIFS support OR logic for wildcards?

No, COUNTIFS only supports AND logic, meaning all specified criteria must be true. To achieve OR logic with wildcards, you need to add two separate COUNTIFS formulas together or use SUMPRODUCT with array operations to handle alternative conditions.

Why is my COUNTIFS returning zero when I expect results?

This often happens due to mismatched data types or hidden spaces. Ensure the text in your range matches the format expected by the wildcard. Also, check for leading or trailing spaces in your data, which can prevent matches. Using the TRIM function to clean data beforehand can resolve this issue.

Can I use wildcards in VLOOKUP?

Yes, VLOOKUP supports wildcards if you set the lookup type argument to FALSE (for exact match). However, it only finds the first occurrence. For counting purposes, COUNTIFS is more appropriate as it returns the total number of matches rather than retrieving a single value.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More