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

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
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,216,028
Messages
6,128,395
Members
449,446
Latest member
CodeCybear

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