Can scripting dictionary alert if certain criteria are met?

Lil Stinker

Board Regular
Joined
Feb 16, 2022
Messages
151
Office Version
  1. 2019
Platform
  1. Windows
Hello @DanteAmor
You provided this code cross referencing serial numbers entered on one sheet with serial numbers listed on another Inventory sheet to me back in June. Provided the numbers match, it updates the Inventory sheet to indicate the number as Out, the Location and Date Out. It also notifies the user if any of the entered serial numbers do not exist anywhere on the Inventory sheet. Everything is working well. Though, now I am wondering if it is possible to alert the user of the current status of a serial number after it is entered in addition to whether it exists or not? For example, if any of the serial numbers entered on RAreceipt (sheet1) are already showing Out on the Inventory (sheet2), have a MsgBox pop up listing those corresponding serial numbers as out and prevent anything being written to the Inventory sheet for those numbers? Basically, if anything on the Inventory sheet is listed as Out, I want to prevent the Inventory sheet from being overwritten with any incorrect data.

I tried playing with If cad = "Out" then MsgBox but that didn't get me anywhere.
VBA Code:
Sub logINV_OUT2()
'''code courtesy of @DanteAmor via MrExcel'''

   Dim a As Variant, b As Variant, c As Variant
   Dim dic As Object, rng As Range, f As Range
   Dim i&, j&, wRow&
   Dim dtOUT As Date, dtRTN As Date, loc As String, cad As String, sNUM As String
   Dim RAnum As Long
  
   Set dic = CreateObject("Scripting.Dictionary")
   Set f = RAreceipt.Range("B:B").Find("SERIAL NUMBERS", , xlValues, xlWhole, xlByRows, xlPrevious, False)
      
   If RAreceipt.Range("AD9").Value = True Then
      a = RAreceipt.Range("B24:O" & f.Row - 1).Value
   ElseIf RAreceipt.Range("AD10").Value = True Then
      a = RAreceipt.Range("P24:Q" & f.Row - 1).Value
   ElseIf RAreceipt.Range("AD11").Value = True Then
      a = RAreceipt.Range("R24:S" & f.Row - 1).Value
   End If
  
   b = Inventory.Range("B2:B" & Inventory.Range("B" & Rows.Count).End(3).Row).Value
   c = Inventory.Range("F2:P" & Inventory.Range("B" & Rows.Count).End(3).Row).Value
   Set rng = Inventory.Range("G1")
  
   dtOUT = RAreceipt.Range("B12").Value
   dtRTN = RAreceipt.Range("B15").Value
   loc = RAreceipt.Range("C8").Value
   RAnum = RAreceipt.Range("Q4").Value
  
   For i = 1 To UBound(b, 1)
      dic(Format(b(i, 1), "@")) = i
   Next
  
   For i = 1 To UBound(a, 1)
      For j = 1 To UBound(a, 2)
      If a(i, j) <> "" Then
         sNUM = Format(a(i, j), "@")
         If dic.exists(sNUM) Then
            wRow = dic(sNUM)
            c(wRow, 1) = "OUT"
            c(wRow, 2) = loc
            c(wRow, 3) = dtOUT
            c(wRow, 4) = dtRTN
            c(wRow, 5) = RAnum
            c(wRow, 6) = "" 'clear previous rtn numbers for items going out
            c(wRow, 11) = "N" 'log new record
            Set rng = Union(rng, Inventory.Range("G" & wRow + 1))
         Else
            cad = cad & a(i, j) & vbCr
         End If
      End If
      Next
   Next
  
   Inventory.Range("F2").Resize(UBound(c, 1), UBound(c, 2)).Value = c
   If cad <> "" Then
      MsgBox "The following equipment was not found in inventory:" & vbNewLine & cad, vbExclamation, "NOT FOUND!"
   ElseIf cad = "" Then
      MsgBox "Existing equipment updated", 0, "Success!"
   End If

End Sub

Here's a small sample of the Inventory on Sheet2.
ItemIDBarcodeDeviceNumberModelDescriptionStatusLocationDateOutReturnDateRAnumberRTNnumberLastReturnInRepairNotesIntakeDateNew Rec
1011018TEQ9190Motorola RadiusUHF 16 Channel Mobile RadioOUTAnywhere11/30/20232/1/2024100103/13/2023
2016018TEQ8870Motorola RadiusUHF 16 Channel Mobile RadioINWAREHOUSE4/3/2023
3017018TEQ8821Motorola RadiusUHF 16 Channel Mobile RadioOUTSomewhere Out There6/2/202310/10/2023100084/26/2023
4023018TEQ9253Motorola RadiusUHF 16 Channel Mobile RadioINWAREHOUSE5/5/2023
5027018TEQ9279Motorola RadiusUHF 16 Channel Mobile RadioINWAREHOUSE6/7/2023
6029018teQ9140Motorola RadiusUHF 16 Channel Mobile RadioINWAREHOUSE10019112/18/20233/13/2023N
7030018TEQ8659Motorola RadiusUHF 16 Channel Mobile RadioINWAREHOUSE10007112/19/20234/3/2023
8052018TEQ8816Motorola RadiusUHF 16 Channel Mobile RadioINWAREHOUSE4/3/2023
90610180000000Motorola RadiusUHF 16 Channel Mobile RadioOUTChicago12/13/20231/5/20241001312/12/20235/2/2023N
10071018TEQ9178Motorola RadiusUHF 16 Channel Mobile RadioINWAREHOUSE3/13/2023
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Looks like DanteAmor is busy. Can any other VBA veterans out there tell me by looking at the code above if there is a way to add in a MsgBox stop when the matching barcode number on the Inventory sheet already indicates "OUT" or "DMG" before the code overwrites the data on the Inventory sheet?

I have no formal training in VBA and only have a vague idea of what the code is doing. Any suggestions would be appreciated.

Thanks in advance!
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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