Count the number of times a particular word appears in every nth column

Roxyz72

New Member
Joined
Sep 14, 2023
Messages
6
Office Version
  1. 2021
Platform
  1. Windows
I have a text-based dataset that follows strict patterns. I want to see how many times a particular word - "Noun", for example - appears in every 5th cell for each row. "Noun" also appears in other cells that I don't want to include in the count, or I'd use COUNTIF for each row. Also, other words may appear in the cell (e.g. "Verb"), which I will count later, once I've figured out the formula. Each row starts in A column, but I started the array in C column because that's where the first instance of "Noun" that I want could be, so I figured I should count from there. I tried the following:
{=SUM(--(MOD(COLUMN($C2:$PC2),5)="Noun"),--($C2:$PC2="Noun"))}
but it seems to count all of the instances of "Noun" in that particular row, while
{=SUMPRODUCT((MOD(COLUMN(C2:PC2),5)="Noun")*($C2:$PC2))}
didn't work at all. I've tried several other variations as well, too many to write down here (those were just the most recent), but none of them returns the correct value.
In one sentence: I'd like to count all of the times that the word "Noun" appears in every 5th cell of each row in the dataset.
Any help would be appreciated.
 
You gave an excellent solution for my earlier problem that looked like this:

=COUNT(FILTER(COLUMN($C2:$PC2),($C2:$PC2=PJ$1)*(MOD(COLUMN($C2:$PC2),5)=3)))

(originally it had '="noun")', but I changed it to PJ$1 because that header cell contains the word "Noun" and I can drag it across to copy the formula for the other words.)

I wanted the same formula, but shifted 2 cells over, so it would start at E2, end at PC2, and every 5th cell again, so I changed it to this:

=COUNT(FILTER(COLUMN($E2:$PC2),($E2:$PC2=PW$1)*(MOD(COLUMN($E2:$PC2),5)=5)))

But it doesn't return anything, even in rows where I know there should be at least 1. What have I done wrong?

I really apologize for bugging you with this, but you've given the best answers and I'm trying to finish my PhD in linguistics before I reach retirement age. Sigh. I did try a bunch of things before messaging you, but I'm clearly missing something.

Thank you for your help with this!
 
Upvote 0

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
It should be
Excel Formula:
=COUNT(FILTER(COLUMN($E2:$PC2),($E2:$PC2=P$1)*(MOD(COLUMN($E2:$PC2),5)=0)))
as mod(5,5) is 0
 
Upvote 1
Hi, here's another option that you don't need to adjust according to the column that you want to start in (which adds some robustness if later down the line you decide to add or delete some columns before column E).

You can change the red 5 to alter the interval between the columns you want to include.

Rich (BB code):
=COUNT(FILTER(COLUMN($E2:$PC2),($E2:$PC2=P$1)*(MOD(SEQUENCE(1,COLUMNS($E2:$PC2)),5)=1)))
 
Upvote 0

Forum statistics

Threads
1,215,076
Messages
6,122,988
Members
449,093
Latest member
Mr Hughes

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top