If I understood you correctly, try placing this together in your Worksheet_Change event codes, right at the top.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim f As Range, s As String, a As String, i As Long, j As Long, placed As Boolean, alerts As Boolean
'set to false to disable MsgBoxes
alerts = True
If Target.Count = 1 And Target.Value <> "" Then
If Not Intersect(Target, Range("BB2")) Is Nothing Then
s = Target.Value
placed = False
Set f = Range("B:R").Find(s, lookat:=xlWhole) 'find for scanned code within columns B:R
If Not f Is Nothing Then
a = f.Address
If f.Offset(1).Value >= 15 Then 'full, find next
Do
Set f = Range("B:R").Find(s, after:=f, lookat:=xlWhole)
If Not f Is Nothing Then
If f.Offset(1).Value < 15 Then 'not full, add 1
placed = True
f.Offset(1).Value = f.Offset(1).Value + 1
If alerts Then MsgBox "[ " & s & " ] stored at cell [ " & f.Address(0, 0) & " ]", vbInformation Or vbOKOnly
End If
End If
Loop While a <> f.Address
If Not placed Then GoTo fNext 'no empty storage left, find next avail space
Else 'not full, add 1
placed = True
f.Offset(1).Value = f.Offset(1).Value + 1
If alerts Then MsgBox "[ " & s & " ] stored at cell [ " & f.Address(0, 0) & " ]", vbInformation Or vbOKOnly
End If
Else 'none found, add to next avail space
fNext:
For i = 2 To 20 Step 2 'rows loop
For j = 2 To 18 'columns B:R
If Cells(i, j).Value = "" Then
placed = True
Cells(i, j).Value = s
Cells(i + 1, j).Value = 1
If alerts Then MsgBox "[ " & s & " ] stored at cell [ " & Cells(i, j).Address(0, 0) & " ]", vbInformation Or vbOKOnly
End If
If placed Then Exit For
Next
If placed Then Exit For
Next
If alerts And Not placed Then MsgBox "No more available storage!", vbCritical Or vbOKOnly
End If
Range("BB2").Select
If placed Then Target.Value = ""
End If
End If
...
... your existing codes here
...
End Sub
The cell the code is reading is BB2. You have to unprotect your sheet and unlock this cell first, since it's locked and protect in your file. You can edit it to be another cell you like.
The idea is to have this as the "input textbox", so have this cell selected, then scan your codes. It will be searched for a match, and sees the number of pallets below it, adds 1 OR find another match or for a next empty cell if it's already 15. I've added explanatory comments to help you understand the codes.
Bookmarks