UDF - FIFO Valuation - Updating balance units as command progresses

Lokesh

New Member
Joined
Jan 24, 2008
Messages
3
I have a UDF which values the stock on FIFO basis and gives the total value at the end. I want the VB scrip to keep updating the balance units in respective rows while running. I am attaching the UDF for reference.

Appreciate if someone can help

Function FIFO(ProductCode As Range, UnitsSold As Range) As Currency
Dim StartCount As Range, UnitCost As Range, Products As Range, Purchaseunits As Range
Dim Counter As Integer, Remainingunits As Long, UnitsAccountedFor As Long
FIFO = 0
Set Products = Range("ProductCode")
Set StartCount = Range("StartCount")
Set UnitCost = Range("UnitCost")
Set Purchaseunits = Range("PurchaseUnits")
UnitsAccountedFor = UnitsSold
For Counter = 1 To StartCount.Rows.Count
If ProductCode = Products(Counter, 1) Then
Remainingunits = Application.WorksheetFunction.Max(0, StartCount(Counter, 1) + _
Purchaseunits(Counter, 1) - UnitsAccountedFor)
FIFO = FIFO + UnitCost(Counter, 1) * Remainingunits
UnitsAccountedFor = UnitsAccountedFor - (StartCount(Counter, 1) + _
Purchaseunits(Counter, 1) - Remainingunits)
End If
Next Counter
End Function
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
You can't use a UDF to alter cell values, it will only return a value to the cell that it's in.
 
Upvote 0
Thanks. Is there any other way I can update the cells - say by running a procedure or something
 
Upvote 0

Forum statistics

Threads
1,223,237
Messages
6,170,928
Members
452,366
Latest member
TePunaBloke

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