Alvaroro84
Board Regular
- Joined
- May 13, 2022
- Messages
- 65
- Office Version
- 2016
- Platform
- Windows
Hello,
I tried to make a macro out of this formula while it works on one cell i cant get it to work with the rest of the column
This formula above works exactly like its suppose to. When i drop it down to the rest of the column it keep this "$C$4:$O$4" constant and changes only this "C5:O5" which is exactly how i want it to work and i tried to build a macro using that same logic. Issue with the bottom macro is that it only stays as =SUM(SUMIFS(C5:O5,$C$4:$O$4,{"Last","chev","tev","Pys"})) and through out the whole column it doesn't change this part "C5:O5"
I tried to make a macro out of this formula while it works on one cell i cant get it to work with the rest of the column
Excel Formula:
=SUM(SUMIFS(C5:O5,$C$4:$O$4,{"Last","chev","tev","Pys"}))
This formula above works exactly like its suppose to. When i drop it down to the rest of the column it keep this "$C$4:$O$4" constant and changes only this "C5:O5" which is exactly how i want it to work and i tried to build a macro using that same logic. Issue with the bottom macro is that it only stays as =SUM(SUMIFS(C5:O5,$C$4:$O$4,{"Last","chev","tev","Pys"})) and through out the whole column it doesn't change this part "C5:O5"
VBA Code:
Sub SumIfsMultipleOR()
Dim sumRange As Range
Dim criteriaRange As Range
Dim result As Double
Dim i As Integer
Set sumRange = Range("C5:O5")
Set criteriaRange = Range("$C$4:$O$4")
Dim criteria As Variant
criteria = Array("Last", "chev", "tev", "Pys")
For i = 0 To UBound(criteria)
result = WorksheetFunction.Sum(result, _
WorksheetFunction.SumIfs(sumRange, criteriaRange, criteria(i)))
Next i
Range("V:V") = result
End Sub