Inventory: FIFO, LIFO and Average Cost

pegbol

Board Regular
Joined
Jan 7, 2005
Messages
192
.
.

Hello,

I need to compare and calculate the Unit Cost Price of my Inventory based on the 3 methods of inventory valuation: FIFO (First In, First Out), LIFO (Last In, First Out) and Average Cost.

Next, I enclose 3 snapshots of each method with the results required (columns color yellow).

Thanks in advance for your help.

regards,
Pedro
.
.
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
.
.

First-In, First-Out (FIFO) -Assumes that the first unit making its way into inventory is the first sold.
inv.xls
ABCDEFGHIJKL
5QUANTITYCOST
6NDATEDOC.DESCRIPTIONUNIT PRICEINOUTBALANCEUNIT COSTDEBITCREDITBALANCE
7101/09/2005BEG. BAL.10.001001001,000.00 1,000.00
8212/09/2005C001IN20.003004006,000.00 7,000.00
9312/09/2005C002IN25.001705704,250.00 11,250.00
10412/09/2005V001OUT5052010.00 500.0010,750.00
11523/09/2005V002OUT37015018.92 7,000.003,750.00
12627/09/2005C003IN30.0070085021,000.00 24,750.00
13729/09/2005V003OUT45040028.33 12,750.0012,000.00
14829/09/2005V004OUT25015030.00 7,500.004,500.00
15902/10/2005C004IN25.003204708,000.00 12,500.00
161003/10/2005V005OUT5042030.00 1,500.0011,000.00
FIFO


.
.
 
Upvote 0
.
.

Last-In, First-Out (LIFO)- Assumes that the last unit making its way into inventory is sold first. The older inventory is therefore left over at the end of the accounting period.
inv.xls
ABCDEFGHIJKL
5QUANTITYCOST
6NDATEDOC.DESCRIPTIONUNIT PRICEINOUTBALANCEUNIT COSTDEBITCREDITBALANCE
7101/09/2005BEG. BAL.10.001001001,000.00 1,000.00
8212/09/2005C001IN20.003004006,000.00 7,000.00
9312/09/2005C002IN25.001705704,250.00 11,250.00
10412/09/2005V001OUT5052025.00 1,250.0010,000.00
11523/09/2005V002OUT37015021.62 8,000.002,000.00
12627/09/2005C003IN30.0070085021,000.00 23,000.00
13729/09/2005V003OUT45040030.00 13,500.009,500.00
14829/09/2005V004OUT25015030.00 7,500.002,000.00
15902/10/2005C004IN25.003204708,000.00 10,000.00
161003/10/2005V005OUT5042025.00 1,250.008,750.00
LIFO


.
.
 
Upvote 0
.
.

Average Cost - It takes the weighted average of all units available for sale. Only divide the total amount by the units on hand at a date.
inv.xls
ABCDEFGHIJKL
5QUANTITYCOST
6NDATEDOC.DESCRIPTIONUNIT PRICEINOUTBALANCEUNIT COSTDEBITCREDITBALANCE
7101/09/2005BEG. BAL.10.001001001,000.00 1,000.00
8212/09/2005C001IN20.003004006,000.00 7,000.00
9312/09/2005C002IN25.001705704,250.00 11,250.00
10412/09/2005V001OUT5052019.74 986.8410,263.16
11523/09/2005V002OUT37015019.74 7,302.632,960.53
12627/09/2005C003IN30.0070085021,000.00 23,960.53
13729/09/2005V003OUT45040028.19 12,684.9811,275.54
14829/09/2005V004OUT25015028.19 7,047.214,228.33
15902/10/2005C004IN25.003204708,000.00 12,228.33
161003/10/2005V005OUT5042026.02 1,300.8910,927.44
AVR COST


.
.
 
Upvote 0
Hi
onto FIFO sheet module
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
With Target
    If .Count > 1 Then Exit Sub
    If Not IsNumeric(.Value) Then Exit Sub
    If Not Intersect(.Cells(1, 1), Range("e:g")) Is Nothing And _
        .Row > 6 Then FIFO
End With
End Sub

onto LIFO sheet module
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
With Target
    If .Count > 1 Then Exit Sub
    If Not IsNumeric(.Value) Then Exit Sub
    If Not Intersect(.Cells(1, 1), Range("e:g")) Is Nothing And _
        .Row > 6 Then LIFO
End With
End Sub

onto AVR COST sheet module
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
With Target
    If .Count > 1 Then Exit Sub
    If Not IsNumeric(.Value) Then Exit Sub
    If Not Intersect(.Cells(1, 1), Range("e:g")) Is Nothing And _
        .Row > 6 Then AVR_COST
End With
End Sub

on standard module
Code:
Sub FIFO()
Dim a As Variant, Cost As Double, sumIn As Double, sumOut As Double, _
        i As Long, ii As Long, n As Long
With Application
    .ScreenUpdating = False
    .Calculation = xlCalculationManual
End With
With Sheets("FIFO")
    .Range("i7", .Cells(Rows.Count, "i").End(xlUp)).ClearContents
    a = .Range("e7", .Cells(Rows.Count, "g").End(xlUp)).Resize(, 5).Value
    n = 1
    For i = LBound(a, 1) To UBound(a, 1)
        If Not IsEmpty(a(i, 3)) Then
            sumOut = a(i, 3)
            For ii = n To i - 1
                If Not IsEmpty(a(ii, 2)) Then
                    sumIn = sumIn + a(ii, 2)
                    If sumIn > sumOut Then
                        Exit For
                    Else
                        Cost = Cost + a(ii, 1) * a(ii, 2)
                        a(ii, 2) = Empty
                    End If
                End If
            Next
            If sumIn - sumOut > 0 Then
                Cost = (Cost + (a(ii, 1) * (a(ii, 2) - (sumIn - sumOut)))) / sumOut
                a(ii, 2) = sumIn - sumOut
            Else
                Cost = Cost / sumOut
            End If
            a(i, 5) = Cost
            sumIn = 0: sumOut = 0: Cost = 0: n = ii
        End If
    Next
    .Range("i7").Resize(UBound(a, 1)) = Application.Index(a, 0, 5)
    Erase a
End With
With Application
    .ScreenUpdating = True
    .Calculation = xlCalculationAutomatic
End With
End Sub


Sub LIFO()
Dim a As Variant, Cost As Double, sumIn As Double, sumOut As Double, _
        i As Long, ii As Long
With Application
    .ScreenUpdating = False
    .Calculation = xlCalculationManual
End With
With Sheets("LIFO")
    .Range("i7", .Cells(Rows.Count, "i").End(xlUp)).ClearContents
    a = .Range("e7", .Cells(Rows.Count, "g").End(xlUp)).Resize(, 5).Value
    For i = LBound(a, 1) To UBound(a, 1)
        If Not IsEmpty(a(i, 3)) Then
            sumOut = a(i, 3)
            For ii = i - 1 To 1 Step -1
                If Not IsEmpty(a(ii, 2)) Then
                    sumIn = sumIn + a(ii, 2)
                    If sumIn > sumOut Then
                        Exit For
                    Else
                        Cost = Cost + a(ii, 1) * a(ii, 2)
                        a(ii, 2) = Empty
                    End If
                End If
            Next
            If sumIn - sumOut > 0 Then
                Cost = (Cost + (a(ii, 1) * (a(ii, 2) - (sumIn - sumOut)))) / sumOut
                a(ii, 2) = sumIn - sumOut
            Else
                Cost = Cost / sumOut
            End If
            a(i, 5) = Cost
            sumIn = 0: sumOut = 0: Cost = 0: n = ii
        End If
    Next
    .Range("i7").Resize(UBound(a, 1)) = Application.Index(a, , 5)
    Erase a
End With
With Application
    .ScreenUpdating = True
    .Calculation = xlCalculationAutomatic
End With
Erase a
End Sub

Sub AVR_COST()
Dim a, i As Long, Bal As Double, Debit As Double
Dim AVcost As Double
With Application
    .Calculation = xlCalculationManual
    .EnableEvents = False
End With
With Sheets("AVR COST")
    a = .Range("e7", .Cells(.Rows.Count, "g").End(xlUp)).Resize(, 3).Value
    .Range("i7", .Cells(.Rows.Count, "i").End(xlUp)).ClearContents
    ReDim Preserve a(1 To UBound(a, 1), 1 To 4)
    For i = LBound(a, 1) To UBound(a, 1)
        If a(i, 2) > 0 Then
            Bal = Bal + a(i, 2)
            Debit = Debit + a(i, 1) * a(i, 2)
            AVcost = Debit / Bal
        ElseIf a(i, 3) > 0 Then
            a(i, 4) = AVcost
            Debit = Debit - a(i, 3) * AVcost
            Bal = Bal - a(i, 3)
        End If
    Next
    .Range("i7").Resize(UBound(a, 1)) = Application.Index(a, 0, 4)
    Erase a
End With
With Application
    .Calculation = xlCalculationAutomatic
    .EnableEvents = True
End With
End Sub

test it hard.
 
Upvote 0
.
.

Amazing jindon !!!! :o


Let me check and test your fantastic code for a while.


Thank you so much for your kind solution.


best regards,
Pedro
.
.
 
Upvote 0
.
.

jindon,

With the little corrections you kindly provided, it works Perfect!. :-D



Again, thank you so much for your valuable help.

Cheers,
Pedro
.
.
 
Upvote 0
Jindon-san, Pegbol,

I need to do exactly the same, so I mimicked the spreadsheet and added Jindon-san's code.
You were referring to some adjustments needed to make the code work properly. Any chance you could post or send me the correctly working code or spreadsheet, as my VBA knowledge is VERY limited, so I was just looking for a simple copy-paste.

Thanks,

My email is nancy.erkens@pandora.be
 
Upvote 0
Do you have the worksheet(s) exactly structured as Pegbol posted?

The amendments I made was error trap when accidentally invalid entry made like
Text entry I think?
 
Upvote 0

Forum statistics

Threads
1,223,956
Messages
6,175,614
Members
452,661
Latest member
Nonhle

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