Adjust countif range according to coulumn data

Lux Aeterna

Board Regular
Joined
Aug 27, 2015
Messages
191
Office Version
  1. 2019
Platform
  1. Windows
Hello everyone!

It's a bit messy in my head so I'll put up an example for you.

Lets say than in the past 4 months, I had 10 tests. I would like my excel to count how many As, Bs, Cs, and Ds I had in January, how many in February etc.

However I'd like to specify the end range of numbers by myself. For January, for example, the countif range would be A6 (that's fixed) to A8. For February A9 to A10, for March A11 to A13, and for April A14 to A15.

So, I'd like my excel to modify the countif function (or any other function you think is appropriate) according to the last test number (F7:F10 range).

For example, G7 cell should have =COUNTIF(C6:C8;"A"), because F7 is 3.
If F7 was 5, I'd like the countif function to auto-change to =COUNTIF(C6:C10;"A")

Accordingly, the G8 cell should have =COUNTIF(C9:C10;"A"), because F8 is 2. And so on.

Overall, I'd like to be able to modify the countif range according to the values I manually insert in F column.

Hope I you can understand it the way I tried to describe it.

PS. If there's a better function to use, I am fine with it. But I'd like to avoid VBAs since I already use some in my file.

1654081610736.png
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Try

G7 copied across and down
=COUNTIF(INDEX($C$6:$C$15,N($F6)+1):INDEX($C$6:$C$15,$F7),G$6)

M.
 
Upvote 0
@Lux Aeterna Another possibility if you can move 'last test number' up and leave F6 blank.

Book1
ABCDEFGHIJ
4
5Test NumberTypeResultLast Test Number Result
61MathsAABCD
72PhysicsBJanuary31200
83LanguageBFebruary50011
94ChemistryCMarch81101
105GeographyDApril91000
116MathsA
127MathsD
138PhysicsB
149ChemistryA
1510ChemistryB
16
Sheet4
Cell Formulas
RangeFormula
G7:J10G7=SUMPRODUCT(($A$6:$A$15>$F6)*($A$6:$A$15<=$F7)*($C$6:$C$15=G$6))
 
Upvote 0
Solution

Forum statistics

Threads
1,214,902
Messages
6,122,161
Members
449,069
Latest member
msilva74

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