This does what you want, and scales! it's in VBa though. I know you asked for worksheet-function but as you don't (didn't) have a suitable answer, I'm offering this.
Remember, there is no undo so make sure you take a back up of your file first.
Option Explicit
Sub WalkThePlank()
Dim startRow As Integer
startRow = 2 'update this if needed Cap'ain, assumes content starts on row 2 as your "headings" be on row 1. Argggghhhh
Dim startCol As Integer
startCol = 69 '69 is for Column E, the first column you want to look at. If this be wrong, then I'll feed myself to the sharks
Dim currentCol As Integer
Dim typeToUse As String
Do While Range("A" & startRow).Value <> ""
currentCol = startCol
Do While Range(Chr(currentCol) & 1).Value <> ""
Dim heading As String
heading = Range(Chr(currentCol) & 1).Value
If (LCase(heading) = "type") Then
typeToUse = Range(Chr(currentCol) & startRow).Value
End If
If (LCase(heading) = "ranking") Then
If LCase(typeToUse) = "a" Then
Range("B" & startRow).Value = Range("B" & startRow).Value + Range(Chr(currentCol) & startRow).Value
End If
If LCase(typeToUse) = "b" Then
Range("C" & startRow).Value = Range("C" & startRow).Value + Range(Chr(currentCol) & startRow).Value
End If
If LCase(typeToUse) = "c" Then
Range("D" & startRow).Value = Range("D" & startRow).Value + Range(Chr(currentCol) & startRow).Value
End If
End If
currentCol = currentCol + 1
Loop
startRow = startRow + 1
Loop
End Sub
How do I add VBA in MS Office?
The only criteria is, from left to right, the Type column must come before the Ranking.
In your screen shot, you have "groups" of 4 columns
Type Name Code Rating
With the above, you could have a group of 2, or 20! It will still work
If you append an additional group of columns to the far right of your data, be it a group of 2, 3, 4 (as you have ) or any other number, it will still work
Before

After running VBa

Then delete the values in TypeA, TypeB and TypeC column and add 2 more columns (I omitted the column called Argh to show how the different structure doesn't matter)

And run the exact same VBa
