Count Consecutive Grades if in Core Courses and Consecutive

anthonyexcel

Active Member
Joined
Jun 10, 2011
Messages
258
Office Version
  1. 365
Platform
  1. Windows
Good morning,

I need to count how many students have concecutive values {"F","D","D+","D-"} if the subject is ("ELA","Science","SS","Math"). I have a formula that I am using the problem is that if a row has one of the values in it but they are not consecutuve it will count it. Any help would be appreciated. Thanks!

VBA Code:
=SUMPRODUCT(--($A$2:$A$12=H2)*($B$2:$B$12={"ELA","Math","SS","Science"})*(MMULT(--ISNUMBER(MATCH($C$2:$F$12,{"D","D-","D+","F"},0)),{1;1;1;1})>1))

IDSubjectQ1Q2Q3Q4
2222111ELAA+BDD22221111
2222111MathADCC333344442
2222111SSCDCC
2222111ScienceDAA-A+
2222111PEDFFF
33334444LanguageCBBB
33334444SSDCBD-
33334444PEDBDC-
33334444ArtCDDD
33334444MathBADD+
33334444ScienceC-DFC
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
What exactly do you mean by consecutive?

And for the screenshot illustrated, what result(s) do you expect to see?
 
Upvote 0
Thanks, StephenCrump,

Consecutive in this case is a {"D","D-","D+","F"} in (Q1 and Q2)
or (Q2 and Q3) or (Q3 and Q4)

Results are:
2222111 =1
33334444 = 2

I have some VBA Code that I use to find if a row has consecutive in them. But was trying to get a formula count.

VBA Code:
Public Function ConsecutiveCount(ByVal r As Range, ByVal s As String) As Long
Dim cell As Range
Dim i As Long
Dim j As Long
    For Each cell In r.Cells
    If (s = "ELA" Or s = "SS" Or s = "Math" Or s = "Science") Then
        If (cell.Value = "D" Or cell.Value = "F" Or cell.Value = "D-" Or cell.Value = "D+") Then
            i = i + 1
            j = Application.max(j, i)
        Else
            i = 0
        End If
    End If
    Next cell
    If j > 1 Then
        ConsecutiveCount = 1
    End If
End Function


IDSubjectQ1Q2Q3Q4
2222111ELAA+BDD1
2222111MathADCC0
2222111SSCDCC0
2222111ScienceDAA-A+0
2222111PEDFFF0
33334444LanguageCBBB0
33334444SSDCBD-0
33334444PEDBDC-0
33334444ArtCDDD0
33334444MathBADD+1
33334444ScienceC-DFC1

VBA Code:
=ConsecutiveCount(C2:F2,B2)
 
Upvote 0
There's probably a better way, but try:

Book1
ABCDEFGHI
1IDSubjectQ1Q2Q3Q4
22222111ELAA+BDD
32222111MathADCC22221111
42222111SSCDCC333344442
52222111ScienceDAA-A+
62222111PEDFFF
733334444LanguageCBBB
833334444SSDCBD-
933334444PEDBDC-
1033334444ArtCDDD
1133334444MathBADD+
1233334444ScienceC-DFC
Sheet3
Cell Formulas
RangeFormula
I3:I4I3=ROWS(FILTER(A$2:A$12,(A$2:A$12=H3)*ISNUMBER(MATCH(B$2:B$12,{"ELA","Math","SS","Science"},0))*(ISNUMBER(MATCH(C$2:C$12,{"D","D-","D+","F"},0))*ISNUMBER(MATCH(D$2:D$12,{"D","D-","D+","F"},0))+ISNUMBER(MATCH(D$2:D$12,{"D","D-","D+","F"},0))*ISNUMBER(MATCH(E$2:E$12,{"D","D-","D+","F"},0))+ISNUMBER(MATCH(E$2:E$12,{"D","D-","D+","F"},0))*ISNUMBER(MATCH(F$2:F$12,{"D","D-","D+","F"},0)))))
 
Upvote 0
Eric W, better way or not! That seems to do the trick! Thank you so much for the help I have been stuck on this so a few days. Appreciate your help!
 
Upvote 0
Happy to help!

And just FYI, here's a shorter way, if it's "better" is debatable!

Book1
ABCDEFGHI
1IDSubjectQ1Q2Q3Q4
22222111ELAA+BDD
32222111MathADCC22221111
42222111SSCDCC333344442
52222111ScienceDAA-A+
62222111PEDFFF
733334444LanguageCBBB
833334444SSDCBD-
933334444PEDBDC-
1033334444ArtCDDD
1133334444MathBADD+
1233334444ScienceC-DFC
Sheet3
Cell Formulas
RangeFormula
I3:I4I3=IFERROR(ROWS(FILTER(A$2:A$12,(A$2:A$12=H3)*ISNUMBER(MATCH(B$2:B$12,{"ELA","Math","SS","Science"},0))*ISNUMBER(MATCH(MMULT(--ISNUMBER(MATCH(C$2:F$12,{"D","D-","D+","F"},0)),{1;2;4;8}),{3,6,7,12,13,14,15},0)))),0)
 
Upvote 0

Forum statistics

Threads
1,224,862
Messages
6,181,457
Members
453,042
Latest member
AbdelrahmanExcel

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