How to Ignore Blanks and Count Duplicates in Excel – 3 Methods

The sample dataset showcases Order Date, Category, Product, and Sold Quantity. There are blank cells in the dataset. To count duplicates ignoring blanks:

Dataset-Count Duplicates in Excel Ignoring Blanks

 


Method 1 – Using the SUMPRODUCT and COUNTIF Functions

Step 1:

  • Enter the following formula in a blank cell (here, G5).
=SUMPRODUCT(--(COUNTIF(B5:E16,B5:E16)>1))

The COUNTIF function takes B5:E16 as range and criteria to pass the count number of each entry in numbers (1 for unique and 2 or greater in case of duplicates).

The SUMPRODUCT function adds occurrences greater than 1 by taking  –(COUNTIF(B5:E16,B5:E16)>1 as an array.

sumproduct sumif 1-Count Duplicates in Excel Ignoring Blanks

Step 2:

  • Press ENTER.

The number of duplicates is displayed in G5.

sumproduct sumif result

Read More: How to Use COUNTIF Formula to Find Duplicates


Method 2 – Using the COUNTIF Function to Count Duplicates in Excel Ignoring Blanks

Step 1:

  • Insert a helper column, Status, and use the formula below:
=COUNTIF(Product,D5)>1

The COUNTIF function returns TRUE or FALSE for B5:B16 (the range named Product) and criteria D5 (each cell) depending on the existence of duplicates.

countif -Count Duplicates in Excel Ignoring Blanks

Step 2:

  • Press ENTER
  • Drag down the Fill Handle to display TRUE or FALSE.

Fill Handle

Step 3:

  • Enter the formula in a blank cell (here, H5).
=COUNTIF(Status,TRUE)

Formula insertion

Step 4:

  • Press ENTER.

This is the output.

Result-Count Duplicates in Excel Ignoring Blanks

 

Related Content: How to Count Duplicate Values Only Once in Excel


Method 3 – Using a VBA Macro to Count Duplicates Ignoring Blanks

Consider the dataset below:

vba dataset-Count Duplicates in Excel Ignoring Blanks

Step 1:

  • Press ALT+F11 to open the Microsoft Visual Basic window.
  • Select Insert and choose Module.

Module insertion

 Step 2:

Copy the following macro in the Module.

Sub Count_Duplicates_IgnoringBlnk()
Range("G5").Formula = "=SUMPRODUCT(--(COUNTIF(B5:E16,B5:E16)>1))"
End Sub

macro

The macro executes the SUMPRODUCT and COUNTIF formula used the previous Method.

Step 3:

  • Press F5 to run the macro.
  • Go back to the worksheet.

You’ll see the count in G5:

vba macro-Count Duplicates in Excel Ignoring Blanks

 Read More: How to Count Repeated Words in Excel


Download Excel Workbook


Related Articles


<< Go Back to Count Duplicates in Excel | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Maruf Islam
Maruf Islam

MARUF ISLAM is an excellent marine engineer who loves working with Excel and diving into VBA programming. For him, programming is like a superhero tool that saves time when dealing with data, files, and the internet. His skills go beyond the basics, including ABACUS, AutoCAD, Rhinoceros, Maxsurf, and Hydromax. He got his B.Sc in Naval Architecture & Marine Engineering from BUET, and now he's switched gears, working as a content developer. In this role, he creates techy content... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo