Hello,
I have the below code to calculate the Cost of Goods Sold. Can anyone help me to frame the logic using Array formulas ? ( For Learning purpose)
Option Explicit
Function FIFO(ByRef Data, ByVal Stock As Double) As Double
Dim ar As Variant
Dim i As Long
Const QtyCol As Long = 1
Const CostCol As Long = 2
ar = Data
For i = LBound(ar, 1) To UBound(ar, 1)
If Stock < ar(i, QtyCol) Then
FIFO = FIFO + Stock * ar(i, CostCol)
Exit Function
Else
FIFO = FIFO + (ar(i, QtyCol) * ar(i, CostCol))
Stock = Stock - ar(i, QtyCol)
If Stock <= 0 Then Exit Function
End If
Next i
End Function
Source : Thesmallman
Thank you
Bookmarks