Lil Stinker
Board Regular
- Joined
- Feb 16, 2022
- Messages
- 151
- Office Version
- 2019
- Platform
- Windows
@DanteAmor Hello again!
Since I only understand basic VBA, I need help figuring out how to update my Inventory sheet with returns based on a few different criteria. Here is the code you provided for locating and updating the serial numbers in inventory when items were going out.
Now, however, I need to mark the items "IN" but the process is a bit different. Not only does it need to find the matching serial number on the Inventory sheet, but it also needs to match the status based on the codes entered into a corresponding range on Sheet1. Based on my post from yesterday, Populate range based on match found between Userform & another range, I need to find the matching serial number and if the corresponding code range has a "Y", mark it "IN" on the Inventory sheet. If it has an "R", mark it as "DMG" on Inventory and for all entries, include the date of return on the Inventory sheet (or Sheet2).
It should look something like this:
Since I only understand basic VBA, I need help figuring out how to update my Inventory sheet with returns based on a few different criteria. Here is the code you provided for locating and updating the serial numbers in inventory when items were going out.
VBA Code:
Sub out_serial_number()
Dim sh1 As Worksheet, sh2 As Worksheet
Dim a As Variant, b As Variant, c As Variant
Dim dic As Object, rng As Range
Dim i&, j&, wRow&
Dim dt As Date, lo As String, cad As String
Dim f As Range
Set sh1 = Sheets("Sheet1")
Set sh2 = Sheets("Sheet2")
Set dic = CreateObject("Scripting.Dictionary")
If sh1.AutoFilterMode Then sh1.AutoFilterMode = False
If sh2.AutoFilterMode Then sh2.AutoFilterMode = False
sh1.Cells.EntireRow.Hidden = False
sh2.Cells.EntireRow.Hidden = False
Set f = sh1.Range("B:B").Find("SERIAL NUMBERS", , xlValues, xlWhole, xlByRows, xlPrevious, False)
a = sh1.Range("B11:O" & f.Row - 1).Value
b = sh2.Range("B2:B" & sh2.Range("B" & Rows.Count).End(3).Row).Value
c = sh2.Range("E2:G" & sh2.Range("B" & Rows.Count).End(3).Row).Value
Set rng = sh2.Range("F1")
dt = sh1.Range("A1").Value
lo = sh1.Range("H1").Value
For i = 1 To UBound(b, 1)
dic(b(i, 1)) = i
Next
For i = 1 To UBound(a, 1)
For j = 1 To UBound(a, 2)
If a(i, j) <> "" Then
If dic.exists(a(i, j)) Then
wRow = dic(a(i, j))
c(wRow, 1) = "Out"
c(wRow, 2) = lo
c(wRow, 3) = dt
Set rng = Union(rng, sh2.Range("F" & wRow + 1))
Else
cad = cad & a(i, j) & vbCr
End If
End If
Next
Next
sh2.Range("E2").Resize(UBound(c, 1), UBound(c, 2)).Value = c
rng.Font.Bold = True
sh2.Range("F1").Font.Bold = False
If cad <> "" Then
MsgBox cad, , "Serial number was not found in inventory"
End If
End Sub
It should look something like this:
Book1.xlsm | |||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | Z | AA | AB | AC | AD | AE | AF | AG | ||||||||||||||||||||
1 | 2/3/2023 | Date Out | 2/13/2023 | Date In | Location | OC Carnival Event | |||||||||||||||||||||||||||||
2 | SERIAL NUMBERS | Apples | Serial Codes | ||||||||||||||||||||||||||||||||
3 | 011 | 4016 | 4264 | 4476 | 4716 | 4945 | 5106 | Y | R | G | Y | Y | |||||||||||||||||||||||
4 | 016 | 4017 | 4275 | 4480 | 4717 | 4948 | 5107 | RD | y | R | Y | ||||||||||||||||||||||||
Sheet1 |
Book1.xlsm | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | |||
1 | Item ID | SerialNumber | Item | Description | Status | Location | DateOut | ReturnDate | ||
2 | 1 | 011 | Apples | Red Delicious | IN | Warehouse | 2/13/2023 | |||
3 | 2 | 016 | Apples | Granny Smith | DMG | Repair | 2/6/2023 | |||
4 | 3 | 4016 | Apples | Granny Smith | DMG | Repair | 2/13/2023 | |||
5 | 4 | 4264 | Apples | Red Delicious | OUT | OC Carnival Event | 2/3/2023 | |||
6 | 5 | 4476 | Oranges | Naval | OUT | OC Carnival Event | 2/3/2023 | |||
7 | 6 | 4945 | Apples | Granny Smith | IN | Warehouse | 2/13/2023 | |||
8 | 7 | 5106 | Pears | Bosch | IN | Warehouse | 2/13/2023 | |||
9 | 8 | 4716 | Pears | Bosch | IN | Warehouse | 2/6/2023 | |||
10 | 9 | 4017 | Oranges | Naval | IN | Warehouse | 2/13/2023 | |||
Inventory |