Userform input box quantity help

TimPslim

New Member
Joined
Apr 10, 2013
Messages
8
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.

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
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Try to replace:

Code:
'copy the data to the database
ws.Cells(iRow, 8).Value = Me.txtUPC.Value
ws.Cells(iRow, 11).Value = Me.txtQTY.Value

with:
Code:
ws.Cells(iRow, 8).Resize(Me.txtQTY.Value,1) = Me.txtUPC.Value
 
Upvote 0

Forum statistics

Threads
1,203,530
Messages
6,055,936
Members
444,837
Latest member
TheBams

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