+ Reply to Thread
Results 1 to 11 of 11

FIFO Inventory- COGS & Inventory Valuation

Hybrid View

  1. #1
    Registered User
    Join Date
    12-07-2005
    Posts
    72

    Re: FIFO Inventory- COGS & Inventory Valuation

    I found the below code on the internet. But it gives me an error "Run Type Mismatch 13. Can anyone help fix this? Can some one suggest how the table structure should be so i could make this work for FIFO valuation?

    Option Explicit
    Sub Update_Inventory()
    Starting_Inventory
    Dim endrow As Long 'last row in range
    Dim Title As String 'book title
    Dim Mycell As Range 'Cell with sold item title
    Dim MyCell2 As Range
    Dim qtySell As Long 'Sell volume in current row
    Dim i As Long 'row counter
    Dim BuySell As Range
    Dim MyRow As Long
    Dim RemInv As String
    Dim invred As Long
    Dim Lastrow As Long 'row above sell transaction
    endrow = Range("A" & Rows.Count).End(xlUp).Row
    Set BuySell = Range("B1:B" & endrow).Find("Sell", LookIn:=xlValues)
    If BuySell Is Nothing Then
    Exit Sub
    End If
    For i = Range(BuySell.Address).Row To endrow Step 1
    Title = Range(BuySell.Address).Offset(0, -1).Value
    qtySell = BuySell.Offset(0, 2).Value
    Lastrow = BuySell.Row - 1
    For Each Mycell In Range("A1:A" & Lastrow)
    Do While MyRow < BuySell.Row
    If Mycell.Value <> Title Then
    GoTo nextmycell:
    ElseIf Mycell.Offset(0, 1).Value = "buy" Then
    RemInv = Range(Mycell.Address).Offset(0, 6).Address
    If Range(RemInv).Value = 0 Then
    GoTo nextmycell:
    ElseIf qtySell <= Range(RemInv).Value Then
    Range(RemInv).Value = Range(RemInv).Value - qtySell
    qtySell = 0
    MyRow = BuySell.Row
    GoTo NextSale:
    ElseIf Range(RemInv).Value < qtySell Then
    invred = Range(RemInv).Value
    Range(RemInv).Value = 0
    qtySell = qtySell - invred
    GoTo nextmycell:
    End If
    End If
    Loop
    nextmycell:
    Next Mycell

    NextSale:
    On Error GoTo ErrorHandler:
    Set BuySell = Range("B" & i & ":B" & endrow). _
    FindNext(BuySell)
    Next
    ErrorHandler:
    End Sub

    Sub Starting_Inventory()
    Dim endrow As Long
    Dim Mycell As Range
    endrow = Range("A" & Rows.Count).End(xlUp).Row
    For Each Mycell In Range("A1:A" & endrow)
    If Mycell.Offset(0, 1).Value = "buy" Then
    Mycell.Offset(0, 6).Value = Mycell.Offset(0, 3).Value
    End If
    Next Mycell
    End Sub
    Thanks
    SD
    Last edited by aromaveda; 08-29-2009 at 01:59 AM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: FIFO Inventory- COGS & Inventory Valuation

    Please edit your post to add code tags.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    12-07-2005
    Posts
    72

    Re: FIFO Inventory- COGS & Inventory Valuation

    i dont know how to do that. let me figure out

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: FIFO Inventory- COGS & Inventory Valuation

    Hello armomaveda,


    How to wrap your Code
    1. Select all your code using the mouse.
    2. Click on the # icon on the toolbar in the Message window. This will automatically wrap the text you selected with the proper Code tags to create a Code Window in your post.

    OR you can also do this manually by placing the tags
    [code] at the start of the first line,
    [/code] at the end of the last line.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  5. #5
    Registered User
    Join Date
    12-07-2005
    Posts
    72

    Re: FIFO Inventory- COGS & Inventory Valuation

    Option Explicit
    Sub Update_Inventory()
    Starting_Inventory
    Dim endrow As Long 'last row in range
    Dim Title As String 'book title
    Dim Mycell As Range 'Cell with sold item title
    Dim MyCell2 As Range
    Dim qtySell As Long 'Sell volume in current row
    Dim i As Long 'row counter
    Dim BuySell As Range
    Dim MyRow As Long
    Dim RemInv As String
    Dim invred As Long
    Dim Lastrow As Long 'row above sell transaction
    endrow = Range("A" & Rows.Count).End(xlUp).Row
    Set BuySell = Range("B1:B" & endrow).Find("Sell", LookIn:=xlValues)
    If BuySell Is Nothing Then
    Exit Sub
    End If
    For i = Range(BuySell.Address).Row To endrow Step 1
    Title = Range(BuySell.Address).Offset(0, -1).Value
    qtySell = BuySell.Offset(0, 2).Value
    Lastrow = BuySell.Row - 1
    For Each Mycell In Range("A1:A" & Lastrow)
    Do While MyRow < BuySell.Row
    If Mycell.Value <> Title Then
    GoTo nextmycell:
    ElseIf Mycell.Offset(0, 1).Value = "buy" Then
    RemInv = Range(Mycell.Address).Offset(0, 6).Address
    If Range(RemInv).Value = 0 Then
    GoTo nextmycell:
    ElseIf qtySell <= Range(RemInv).Value Then
    Range(RemInv).Value = Range(RemInv).Value - qtySell
    qtySell = 0
    MyRow = BuySell.Row
    GoTo NextSale:
    ElseIf Range(RemInv).Value < qtySell Then
    invred = Range(RemInv).Value
    Range(RemInv).Value = 0
    qtySell = qtySell - invred
    GoTo nextmycell:
    End If
    End If
    Loop
    nextmycell:
    Next Mycell
    
    NextSale:
    On Error GoTo ErrorHandler:
    Set BuySell = Range("B" & i & ":B" & endrow). _
    FindNext(BuySell)
    Next
    ErrorHandler:
    End Sub
    
    Sub Starting_Inventory()
    Dim endrow As Long
    Dim Mycell As Range
    endrow = Range("A" & Rows.Count).End(xlUp).Row
    For Each Mycell In Range("A1:A" & endrow)
    If Mycell.Offset(0, 1).Value = "buy" Then
    Mycell.Offset(0, 6).Value = Mycell.Offset(0, 3).Value
    End If
    Next Mycell
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1