VBA Help

JakeaB

New Member
Joined
Oct 6, 2022
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Hello,

I am attempting to write code for an inventory management system for my company. I need help to write code to reduce my inventory by the amount requested. I have a continually expanding table based on the items added to the request, so the code will need to find all of the item ID's on the table and reduce the quantity on another table based on the correlating item ID. The two tables are on separate sheet tabs.
 

Attachments

  • Request Table.png
    Request Table.png
    14.9 KB · Views: 6

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Hello and welcome to the Forum. It is hard to work with a picture. It would be easier to help if you could use the XL2BB add-in (icon in the menu) to attach screenshot (not pictures) of both sheets. Alternately, you could upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. Explain in detail what you want to do referring to specific cells, rows, columns and sheets using a few examples from your data (de-sensitized if necessary).
 
Upvote 0
Hello and welcome to the Forum. It is hard to work with a picture. It would be easier to help if you could use the XL2BB add-in (icon in the menu) to attach screenshot (not pictures) of both sheets. Alternately, you could upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. Explain in detail what you want to do referring to specific cells, rows, columns and sheets using a few examples from your data (de-sensitized if necessary).
 
Upvote 0
You want to reduce the values in column M in the Linked Inventory by the amount in column K in ScopeOfWork for each Item ID? Is this correct? What happens if there is zero inventory for an Item ID in the Linked Inventory?
 
Upvote 0
You want to reduce the values in column M in the Linked Inventory by the amount in column K in ScopeOfWork for each Item ID? Is this correct? What happens if there is zero inventory for an Item ID in the Linked Inventory?
That is correct. No need to account for 0 inventory as there is a notice when selecting an item, for the amount currently in stock. Also we are tracking inventory based on EOQ so that we have base reorder levels. This is just a preliminary sheet so all stock values can be disregarded.
 
Upvote 0
You want to reduce the values in column M in the Linked Inventory by the amount in column K in ScopeOfWork for each Item ID? Is this correct? What happens if there is zero inventory for an Item ID in the Linked Inventory?
Keep in mind that items can be continually added to the "tblList" Table on ScopeOfWork So the code would need to read all item ID's in the table
 
Upvote 0
Try:
VBA Code:
Sub UnpdateInventory()
    Application.ScreenUpdating = False
    Dim srcWS As Worksheet, desWS As Worksheet, ID As Range, fnd As Range
    Set srcWS = Sheets("ScopeOfWork")
    Set desWS = Sheets("Linked Inventory")
    For Each ID In srcWS.Range("H6", srcWS.Range("H" & Rows.Count).End(xlUp))
        Set fnd = desWS.Range("A:A").Find(ID, LookIn:=xlValues, lookat:=xlWhole)
        If Not fnd Is Nothing Then
            fnd.Offset(, 12).Value = fnd.Offset(, 12).Value - ID.Offset(, 3).Value
        Else
            MsgBox ("Item Id " & ID & " not found.")
        End If
    Next ID
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
Try:
VBA Code:
Sub UnpdateInventory()
    Application.ScreenUpdating = False
    Dim srcWS As Worksheet, desWS As Worksheet, ID As Range, fnd As Range
    Set srcWS = Sheets("ScopeOfWork")
    Set desWS = Sheets("Linked Inventory")
    For Each ID In srcWS.Range("H6", srcWS.Range("H" & Rows.Count).End(xlUp))
        Set fnd = desWS.Range("A:A").Find(ID, LookIn:=xlValues, lookat:=xlWhole)
        If Not fnd Is Nothing Then
            fnd.Offset(, 12).Value = fnd.Offset(, 12).Value - ID.Offset(, 3).Value
        Else
            MsgBox ("Item Id " & ID & " not found.")
        End If
    Next ID
    Application.ScreenUpdating = True
End Sub
It works perfectly! Thank you so much!
 
Upvote 0

Forum statistics

Threads
1,215,480
Messages
6,125,047
Members
449,206
Latest member
Healthydogs

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