How do I write a formula to count within a calculated range?

Arth

New Member
Joined
Oct 20, 2005
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Hi - I'm trying to write a formula that will count the number of subs below a sub but failing. Need some help pls on how to do this.

An extract of my data sample is below.
For line 1 it will be all records i.e. 27 as below
For line 2 it should return only 1 as it only has 1 sub as line 4 is a 2 and therefore not a sub of line 2
For line 3 no subs so should return a 'nil'
For line 4 there are 24 records counted before the next record of 2 or lower

I need a formula I can drag down the page (col. 3) that can calculate the count of subs.

thanks

SubSub CheckCount of SubsLogic
1​
Yes
27​
= count number of items > 1
2​
Yes
1​
= count number of items > 2
3​
No
2​
Yes
24​
= count number of items > 2
3​
No
3​
No
3​
No
3​
No
3​
No
3​
No
3​
No
3​
No
3​
No
3​
No
3​
No
3​
No
3​
No
3​
No
3​
No
3​
No
3​
Yes
2​
= count number of items > 3
4​
Yes
1​
= count number of items > 4
5​
No
3​
No
3​
No
3​
No
3​
Yes
1​
= count number of items > 4
4​
No
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
And how is that meant to do what the OP has asked for?
 
Upvote 0
What version of Excel are you using?

I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
 
Upvote 0
And how is that meant to do what the OP has asked for?
He wants to calculate the count of subs by sub, because I talked to him about this functions.
Sumif to he sum the subs and subtotal to he compare in a dynamic way
 
Upvote 0
Hi - I'm trying to write a formula that will count the number of subs below a sub but failing. Need some help pls on how to do this.

An extract of my data sample is below.
For line 1 it will be all records i.e. 27 as below
For line 2 it should return only 1 as it only has 1 sub as line 4 is a 2 and therefore not a sub of line 2
For line 3 no subs so should return a 'nil'
For line 4 there are 24 records counted before the next record of 2 or lower

I need a formula I can drag down the page (col. 3) that can calculate the count of subs.

thanks

SubSub CheckCount of SubsLogic
1​
Yes
27​
= count number of items > 1
2​
Yes
1​
= count number of items > 2
3​
No
2​
Yes
24​
= count number of items > 2
3​
No
3​
No
3​
No
3​
No
3​
No
3​
No
3​
No
3​
No
3​
No
3​
No
3​
No
3​
No
3​
No
3​
No
3​
No
3​
No
3​
Yes
2​
= count number of items > 3
4​
Yes
1​
= count number of items > 4
5​
No
3​
No
3​
No
3​
No
3​
Yes
1​
= count number of items > 4
4​
No
He wants to calculate the count of subs by sub, because I talked to him about this functions.
Sumif to he sum the subs and subtotal to he compare in a dynamic way
sorry how do I write the formula to do this?
 
Upvote 0
How about
Fluff.xlsm
ABC
1SubSub CheckCount of Subs
21Yes27
32Yes1
43No 
52Yes24
63No 
73No 
83No 
93No 
103No 
113No 
123No 
133No 
143No 
153No 
163No 
173No 
183No 
193No 
203No 
213No 
223Yes2
234Yes1
245No 
253No 
263No 
273No 
283Yes1
294No 
30
Main
Cell Formulas
RangeFormula
C2:C29C2=IF(A3>A2,MIN(IFERROR(XMATCH(SEQUENCE(A2),A3:A5000)-1,LOOKUP(2,1/($A$1:$A$5000<>""),ROW($A$1:$A$5000)-ROW()))),"")
 
Upvote 1
Solution
How about
Fluff.xlsm
ABC
1SubSub CheckCount of Subs
21Yes27
32Yes1
43No 
52Yes24
63No 
73No 
83No 
93No 
103No 
113No 
123No 
133No 
143No 
153No 
163No 
173No 
183No 
193No 
203No 
213No 
223Yes2
234Yes1
245No 
253No 
263No 
273No 
283Yes1
294No 
30
Main
Cell Formulas
RangeFormula
C2:C29C2=IF(A3>A2,MIN(IFERROR(XMATCH(SEQUENCE(A2),A3:A5000)-1,LOOKUP(2,1/($A$1:$A$5000<>""),ROW($A$1:$A$5000)-ROW()))),"")
this is brilliant, thankyou. It works amazing on my 400 line population. Could not have written this one on my own. Appreciated!!!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,444
Messages
6,124,893
Members
449,194
Latest member
JayEggleton

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