Chrisg33

New Member
Joined
Mar 10, 2018
Messages
4
Recently got promoted at my job to start and manage inventory. We have a set up excel sheet but currently have to manually update inventory when a product leaves. To keep it short for example product one uses 5 screws, 2 nuts, and one hinge. How would I make it so that if I enter that we sold 5 units of product one that it would remove the respective quantities of screws, nuts, and hinges in the main inventory page? Thank you for your time.
 
Hi,
I updated my code. You need to open VBE (ALT+F11) and double click on Sheet name then add code. E.g.:

Prt_Screen01.jpg



Code:
Option Explicit


Private Sub Worksheet_Change(ByVal Target As Range)


Dim Rng As Range, i As Long, Screw_ As Long, Nut_ As Long, Hinge_ As Long, j As Long, Rng2 As Range
Dim ScrewSzorzo_ As Long, NutSzorzo_ As Long, HingeSzorzo_ As Long


Set Rng = Range("h2:h3")
Set Rng2 = ActiveSheet.UsedRange


If Not Intersect(Target, Rng) Is Nothing Then
    For i = 2 To Rng2.Rows.Count
        Select Case Target.Offset(0, -2) 'Rng2.Cells(i, 6)
            Case "Product01"
                ScrewSzorzo_ = 5 'change if necessary
                NutSzorzo_ = 2 'change if necessary
                HingeSzorzo_ = 1 'change if necessary
            Case "Product02"
                ScrewSzorzo_ = 4 'change if necessary
                NutSzorzo_ = 3 'change if necessary
                HingeSzorzo_ = 2 'change if necessary
        End Select
    Next i
    j = Target.Value
    Screw_ = ScrewSzorzo_ * j
    Nut_ = NutSzorzo_ * j
    Hinge_ = HingeSzorzo_ * j
    
    For i = 2 To Rng2.Rows.Count
        Select Case Rng2.Cells(i, 1)
            Case "Screw"
                Rng2.Cells(i, 3) = Rng2.Cells(i, 3) - Screw_
            Case "Nut"
                Rng2.Cells(i, 3) = Rng2.Cells(i, 3) - Nut_
            Case "Hinge"
                Rng2.Cells(i, 3) = Rng2.Cells(i, 3) - Hinge_
        End Select
    Next i
End If


End Sub

You can delete range J1:N3 on worksheet because these values are hard coded in VBA code above.

Regards,
 
Last edited:
Upvote 0

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

Forum statistics

Threads
1,215,842
Messages
6,127,227
Members
449,371
Latest member
strawberrish

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