Results 1 to 8 of 8

How to Update Stock quantity if I sold items?

Threaded View

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

    The attached workbook contains the following macros. The main macro adjusts the stock level based on the current stock less what has been sold. The other macro is in the Worksheet_Change() event which checks the entry and then calls the main macro.

    Stock Level (main macro)
    Function StockLevel(Item_Name As String, Qty_Sold As Double) As Variant
     
      Dim OnHand As Double
      Dim Result As Range
      Dim Rng As Range
      
        Set Rng = Worksheets("Sheet1").Range("Batteries")
        
        If Item_Name = "" Or Qty_Sold < 0 Then
           StockLevel = ""
           Exit Function
        End If
        
          Set Result = Rng.Find(What:=Item_Name, After:=Rng.Cells(1, 1))
            If Result Is Nothing Then
               StockLevel = ""
               Exit Function
            End If
            
          OnHand = Result.Offset(0, 1).Value - Qty_Sold
            If OnHand <= 0 Then
               Result.Offset(0, 1) = 0
               StockLevel = 0
            Else
               Result.Offset(0, 1).Value = OnHand
               StockLevel = OnHand
            End If
                         
    End Function
    Worksheet_Change() Event Macro
    Private Sub Worksheet_Change(ByVal Target As Range)
    
      If Not Intersect(Target, Range("B2:B6")) Is Nothing Then
         Call StockLevel(Target.Offset(0, -1).Value, Target.Value)
      End If
      
    End Sub
    Sincerely,
    Leith Ross
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

There are currently 2 users browsing this thread. (0 members and 2 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