Code:
Private Sub TestFunctions()
Dim flag As Range, EB As Range
Set flag = Range("H82")
Set EB = Range("K84")
MsgBox SumCells(flag, EB)
End Sub
Function SumCells(flag As Range, EB As Range)
Dim sumRng As Range
Dim a As Currency, b As Currency
Set sumRng = flag
b = Abs(EB)
a = flag
Do Until a >= b
If a <> b Then
Set sumRng = Union(sumRng, Range(RangeOffset(sumRng)))
a = WorksheetFunction.Sum(sumRng)
End If
Loop
SumCells = sumRng
End Function
The function's job is to return a range of cells. i.e. A1:Z1, NOT the amounts in the cells.
Last edited: