How do I create a fifo function in Excel?

Here's what I came up with to start, it doesn't do any error checking and date matching, but it works Public Function fifo(SoldToDate As Double, Purchase_Q As Range, _ Purchase_price As Range) As Double Dim RowOffset As Integer Dim CumPurchase As Double Dim Quantity As Range Dim CurrentPrice As Range CumPurchase = 0 RowOffset = -1 For Each Quantity In Purchase_Q CumPurchase = CumPurchase + Quantity. Value RowOffset = RowOffset + 1 If CumPurchase > SoldToDate Then Exit For Next 'if sold > total_purchase, use the last known price. Set CurrentPrice = Purchase_price.

Cells(1, 1). Offset(RowOffset, 0) fifo = CurrentPrice. Value End Function.

Here's what I came up with to start, it doesn't do any error checking and date matching, but it works. Public Function fifo(SoldToDate As Double, Purchase_Q As Range, _ Purchase_price As Range) As Double Dim RowOffset As Integer Dim CumPurchase As Double Dim Quantity As Range Dim CurrentPrice As Range CumPurchase = 0 RowOffset = -1 For Each Quantity In Purchase_Q CumPurchase = CumPurchase + Quantity. Value RowOffset = RowOffset + 1 If CumPurchase > SoldToDate Then Exit For Next 'if sold > total_purchase, use the last known price.

Set CurrentPrice = Purchase_price. Cells(1, 1). Offset(RowOffset, 0) fifo = CurrentPrice.

Value End Function.

I had a similar problem finding the "most recent exchange rate" via VBA. This is my code, maybe it can inspire you ... Function GetXRate(CurCode As Variant, Optional CurDate As Variant) As Variant Dim Rates As Range, chkDate As Date Dim Idx As Integer GetXRate = CVErr(xlErrNA) ' set to N/A error upfront If VarType(CurCode) vbString Then Exit Function ' if we didn't get a string, we terminate If IsMissing(CurDate) Then CurDate = Now() ' if date arg not provided, we take today If VarType(CurDate) vbDate Then Exit Function ' if date arg provided but not a date format, we terminate Set Rates = Range("Currency") ' XRate table top-left is a named range Idx = 2 ' 1st row is header row ' columns: 1=CurCode, 2=Date, 3=XRate Do While Rates(Idx, 1) "" If Rates(Idx, 1) = CurCode Then If Rates(Idx, 2) = "" Then GetXRate = Rates(Idx, 3) ' rate without date is taken at once Exit Do ElseIf Rates(Idx, 2) > chkDate And Rates(Idx, 2).

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions