Function Problems

How to Use COUNTIF for Nonoverlapping 40-Row Groups in Excel

Ayan MasoodAyan Masood Oct 22, 2026 871 views

Question details

The user needs a way to calculate COUNTIF for consecutive, non-overlapping groups of 40 rows without manually adjusting the formula.

How to Use COUNTIF for Nonoverlapping 40-Row Groups in Excel
Product
Excel
Device & OS
not provided
Scenario
When analyzing data divided into consistent 40-row blocks, the user attempts to drag the COUNTIF formula down to auto-populate the results.
Observed behavior
Excel's standard autofill shifts the range down by exactly one row at a time (e.g., J2:J41 becomes J3:J42), resulting in overlapping ranges rather than consecutive 40-row jumps (J42:J81).
Before you start

Verify that your target data is organized without blank spacer rows in the middle of your 40-row blocks, and locate an empty column where you will enter your counting formulas.

Solution 1Recommended

Use INDEX and ROW to Force Non-overlapping Ranges

Combine the INDEX and ROW functions to calculate the start and end of your range dynamically, effectively skipping 40 rows each time the formula is dragged down.

By default, Excel relative references change by exactly one row when dragged down. To make a formula jump by 40 rows automatically, we must mathematically define the range using the ROW function to create a multiplier, and use the INDEX function to translate that math into a valid cell reference.

1
Select the starting cell

Click on the cell where you want the very first calculation to appear (for example, row 2 in an empty column).

2
Enter the dynamic COUNTIF formula

Type the following formula: =COUNTIF(INDEX(J:J,40*(ROW(A2)-ROW(A$2))+2):INDEX(J:J,40*(ROW(A2)-ROW(A$2))+41),"Yes"). Be sure to replace "Yes" with the actual criteria you are trying to count.

3
Apply the calculation

Press the Enter key. The cell will now display the count of your criteria specifically for the first block (cells J2 through J41).

4
Autofill the remaining blocks

Click the small square fill handle at the bottom right corner of the formula cell and drag it down. The subsequent cells will now calculate J42:J81, J82:J121, and so on without overlapping.

Use INDEX and ROW to Force Non-overlapping Ranges
How this works: The section 40*(ROW(A2)-ROW(A$2)) evaluates to 0 in the first row, keeping the start at row 2. When dragged down one cell, the reference A2 becomes A3, making the calculation 40*(1), which perfectly shifts the starting position down by 40 rows.
Solve Complex Formulas Easily with WPS

Easily Handle Complex Data Operations in WPS Spreadsheet

WPS Spreadsheet provides robust native support for advanced nested functions, allowing you to use INDEX, ROW, and COUNTIF together to manipulate datasets smoothly just as you would in Microsoft Excel.

  1. 1. Open your data file: Launch WPS Spreadsheet and open the .xlsx file containing your dataset.
  2. 2. Input the nested formula: Select the target cell, type the formula combining COUNTIF, INDEX, and ROW to define your 40-row block, and press Enter.
  3. 3. Drag to calculate: Use the smart fill handle in the lower right corner to drag the formula down, automatically generating your non-overlapping totals.
100% compatible with Microsoft Excel (.xlsx) formats and functions.Flawlessly executes complex nested logic like INDEX/MATCH and dynamic array math.Lightweight architecture ensures fast calculation on large data blocks.Familiar user interface makes formula writing intuitive and stress-free.
microsoft office alternative - wps office

Frequently Asked Questions

Can I use the OFFSET function to create non-overlapping ranges?

Yes, you can use OFFSET like this: =COUNTIF(OFFSET($J$2, (ROW(A1)-1)*40, 0, 40), "Yes"). However, OFFSET is a volatile function that recalculates every time any change is made in the workbook, which can slow down performance on large datasets. The INDEX method is highly recommended for better speed.

How do I change the group size from 40 rows to 15 rows?

To change the block size, replace the '40' in the multiplier. For 15 rows, the formula's start calculation would be 15*(ROW(A2)-ROW(A$2))+2, and the end calculation would be +16. Simply ensure the difference between the starting and ending index numbers correctly reflects your desired range size.

Why does my autofill just copy the exact same numbers?

If autofill copies the same result, make sure Calculation Options in the Formulas tab is set to 'Automatic' rather than 'Manual'. If it is set to automatic, double-check your formula to ensure you did not accidentally lock the relative row references (e.g., using $A$2 instead of A2 inside the ROW function).

Can I use this same logic to SUM non-overlapping groups instead of counting them?

Absolutely. You can replace the COUNTIF function with SUM or SUMIF while leaving the INDEX(J:J...):INDEX(J:J...) range construction intact. This allows you to add up values in perfectly divided, non-overlapping chunks.