I have a Userform with 2 text boxes, first box asks for a UPC and the second a quantity. I've got my code where it then populates column "H" with the UPC and then column "K" with the quantity, but I would rather it just copy the UPC in column "H" the number of times in the quantity box.
For instance:
UPC: 12345
QTY: 3
Should come out as
12345
12345
12345
Instead of
12345 3
Here's the code I have now if anyone can help me out.
For instance:
UPC: 12345
QTY: 3
Should come out as
12345
12345
12345
Instead of
12345 3
Here's the code I have now if anyone can help me out.
Code:
Private Sub cmdAdd_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Scan")
'find first empty row in database
iRow = ws.Range("H:H").Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
'check for a UPC
If Trim(Me.txtUPC.Value) = "" Then
Me.txtUPC.SetFocus
MsgBox "Please enter a UPC or Press Done"
Exit Sub
End If
If Trim(Me.txtQTY.Value) = "" Then
Me.txtQTY.SetFocus
MsgBox "Please enter a Quantity"
Exit Sub
End If
'copy the data to the database
ws.Cells(iRow, 8).Value = Me.txtUPC.Value
ws.Cells(iRow, 11).Value = Me.txtQTY.Value
'reset the boxes
Me.txtUPC.Value = ""
Me.txtQTY.Value = "1"
Me.txtUPC.SetFocus
End Sub
Private Sub cmdClose_Click()
Unload Me
End Sub
Private Sub txtQTY_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Not IsNumeric(Me.txtQTY.Value) Then
MsgBox "Please Enter Only Numeric Values"
Cancel = True
End If
End Sub