Sub SumIf() Range("E3:Z4").ClearContents intRow = Range("B3").End(xlDown).Row strSeib = Range("B4") C = 6 Cells(3, C - 1).Value = strSeib intCol = 5 For i = 5 To intRow Range("B" & i).Select If Cells(3, 6) <> "" Then intCol = Range("E3").End(xlToRight).Column End If If Range("B" & i) = Range("B" & i - 1) Then GoTo Jump Else For i3 = 5 To intCol If Range("B" & i) = Cells(3, i3) Then GoTo Jump End If If Range("B" & i) <> Cells(3, i3) Then If intCol = 5 Then Cells(3, C).Value = Range("B" & i) C = C + 1 End If If intCol > 5 And i3 = intCol Then GoTo Jump3 GoTo Jump2 Else Cells(3, C).Value = Range("B" & i) C = C + 1 GoTo Jump End If Jump3: Cells(3, C).Value = Range("B" & i) C = C + 1 GoTo Jump Jump2: Next End If Jump: Next For i2 = 5 To intCol intTot = Application.WorksheetFunction.SumIf(Range("B4:C20"), Cells(3, i2), Range("C4:C20")) Cells(4, i2).Value = intTot Next Total = Application.WorksheetFunction.Sum(Range(Cells(4, 5), Cells(4, intCol))) Cells(4, intCol + 1).Value = Total End Sub