Function Problems

How to Count Columns Containing Data in an Excel Range

Khadija KhanKhadija Khan Nov 4, 2026 869 views

Question details

The user needs to calculate the total number of columns within specific ranges that contain at least one non-blank cell, rather than counting every individual populated cell.

How to Count Columns Containing Data in an Excel Range
Product
Excel
Device & OS
not provided
Scenario
Calculating metrics such as 'Days Worked' across multiple disconnected ranges (e.g., F2:K15 and F17:K32) where each column represents a day and any data entered in that column means the day should be counted.
Observed behavior
Standard counting functions like COUNT or COUNTA return the total number of non-empty cells. The user requires a method to evaluate whole columns and return a count of populated columns (e.g., returning 6 if six columns contain data).
Before you start

Identify the exact cell ranges you need to evaluate (such as F2:K15) and decide whether you prefer using a built-in array formula or creating a custom VBA macro.

Solution 1Recommended

Use an Array Formula with SUMPRODUCT and MMULT

This method uses built-in functions to evaluate the range without needing to enable macros, making it ideal for standard spreadsheet sharing.

Combining SUMPRODUCT and MMULT allows Excel to perform matrix multiplication. This evaluates which columns in a two-dimensional range contain at least one non-blank cell and sums the resulting true/false array.

1
Select the destination cell

Click on the cell where you want the final column count (e.g., your 'Days Worked' total) to appear.

2
Input the array formula

Type the formula combining SUMPRODUCT, MMULT, and TRANSPOSE targeted at your specific range. For example, evaluating F2:K15 checking for non-blank cells.

3
Confirm the formula

Press Enter. In some older versions of Excel, you may need to press Ctrl + Shift + Enter to properly execute it as an array formula.

Use an Array Formula with SUMPRODUCT and MMULT
Adding Multiple Ranges: If you need to evaluate multiple ranges like F2:K15 and F17:K32, you can create the formula for the first range, add a plus sign (+), and append the formula for the second range.
Work Smarter with WPS

Calculate Complex Data Easily with WPS Spreadsheet

WPS Spreadsheet fully supports advanced array formulas and VBA macros, empowering you to seamlessly count columns containing data just as you would in Microsoft Excel.

  1. 1. Open your file in WPS Spreadsheet: Launch WPS Office and open your existing spreadsheet containing the data ranges.
  2. 2. Select your output cell: Click on the cell where you want to display the total number of columns containing data.
  3. 3. Enter the formula: Type in your SUMPRODUCT/MMULT array formula or your custom =ColCount() function.
  4. 4. Get instant results: Press Enter to execute the calculation and view your accurately counted columns instantly.
Fully compatible with Microsoft Excel formulas like SUMPRODUCT, MMULT, and COUNTIFRobust support for VBA macros to create custom functions like ColCountFree, lightweight, and user-friendly interfaceSeamless processing of complex matrix multiplication and array operations
microsoft office alternative - wps office

Frequently Asked Questions

Can I use COUNTIF to count columns with data?

A standard COUNTIF function evaluates individual cells based on a condition, not entire columns at once. However, it can be nested inside an array formula (like SUMPRODUCT) to help evaluate matrix data across columns.

Why does my custom ColCount function return a #NAME? error?

The #NAME? error usually occurs if macros are disabled in your security settings, if the module containing the VBA code wasn't saved correctly, or if there is a typo in the function name when typed into the cell.

How do I modify this to count completely empty columns instead?

To count empty columns, you can either subtract the populated column count from the total number of columns in your range (e.g., using COLUMNS(F2:K15)), or adjust your array formula logic to count columns where the non-blank cell count equals zero.