youracct

New Member
Joined
Feb 21, 2018
Messages
10
I would appreciate any assistance I could get with this inventory formula. Thanks!



Purchased tonscost per tontons usedFIFO ending value
25858.23.3518158583518.081

<tbody>
</tbody>


I was using the following vba code to create a FIFO formula, but it does not work with decimals in column a for some reason.

=FIFO(A2,B2,C2,TRUE)

Admittedly I am quite new to VBA and would prefer to use formulas and even helper columns but this seems to work smoother except for the decimals throw everything off...and we must have the decimals for accuracy.

Option Explicit


Function FIFO(PurchaseUnits As Range, UnitCost As Range, UnitsSold As Range, Optional blnAscending As Boolean = False) As Double
Dim Counter As Long, UnitsAccountedFor As Long
Dim varPurchased, varCost
FIFO = 0
UnitsAccountedFor = Application.Sum(UnitsSold)
varPurchased = PurchaseUnits.Value
varCost = UnitCost.Value
If blnAscending Then
Counter = LBound(varPurchased, 1)
Do Until UnitsAccountedFor = 0
If varPurchased(Counter, 1) = 0 Then
Counter = Counter + 1
Else
varPurchased(Counter, 1) = varPurchased(Counter, 1) - 1
UnitsAccountedFor = UnitsAccountedFor - 1
End If
Loop
Else
Counter = UBound(varPurchased, 1)
Do Until UnitsAccountedFor = 0
If varPurchased(Counter, 1) = 0 Then
Counter = Counter - 1
Else
varPurchased(Counter, 1) = varPurchased(Counter, 1) - 1
UnitsAccountedFor = UnitsAccountedFor - 1
End If
Loop
End If
FIFO = Application.SumProduct(varPurchased, varCost)
End Function
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
youracct, I have just tried the function with the example you've provided & it's working fine even with decimals. Just try to increase the range instead of choosing 1 row

=FIFO(A2:A3,B2:B3,C2:C3,TRUE)
 
Upvote 0

Forum statistics

Threads
1,215,327
Messages
6,124,290
Members
449,149
Latest member
mwdbActuary

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top