PDA

View Full Version : repeated user input



scb998
03-05-2013, 08:37 PM
Hello All,

Now that ive fixed my error - i can get onto the crux of my issue.

I have (with help) created code that allows a user to select an item and a quantiy, which is placed in a pre- formatted worksheet (see attached file).

This procedure is to repeat until there are the specified number of items in the spreadsheet.

at the moment, the code is jsutnlooping continuously without allowing me to re-select a different item. :/

is anyone able to prode some adive, or a section of code that could rectify my problem?

here is my code:Private Sub CommandButton1_Click()
Dim formula As String
Dim ws As Worksheet
Set ws = Worksheets("Sheet4")
row = 21
col = 1
On Error Resume Next
Do
If Items_entered <> Items Then

quantity = ComboBox2.Value
prod_desc = ComboBox1.Value
Cells(row, col).Value = quantity
col = col + 1
Cells(row, col).Value = prod_desc
Cells(row, col).Select
varlookup = ActiveCell.Address
col = col + 1
Cells(row, col).Select
Cells(row, col).Value = Application.WorksheetFunction.VLookup(prod_desc, Worksheets("Sheet4").Range("a2:b50"), 2, False)
col = col + 1
Cells(row, col).Value = Cells(row, col - 1).Value * quantity
UserForm1.Hide
MsgBox ("item Added to Invoice")
row = row + 1
col = 1
Items_entered = Items_entered + 1
End If
UserForm1.Show
Loop Until Items_entered = Items
End Sub

patel
03-06-2013, 02:20 AM
you don't need loop
Private Sub CommandButton1_Click()
Dim formula As String
Dim ws As Worksheet
Set ws = Worksheets("Sheet4")
row = 21
col = 1
On Error Resume Next
quantity = ComboBox2.Value
prod_desc = ComboBox1.Value
Cells(row, col).Value = quantity
col = col + 1
Cells(row, col).Value = prod_desc
Cells(row, col).Select
varlookup = ActiveCell.Address
col = col + 1
Cells(row, col).Select
Cells(row, col).Value = Application.WorksheetFunction.VLookup(prod_desc, Worksheets("Sheet4").Range("a2:b50"), 2, False)
col = col + 1
Cells(row, col).Value = Cells(row, col - 1).Value * quantity
MsgBox ("item Added to Invoice")
row = row + 1
col = 1
Items_entered = Items_entered + 1
If Items_entered = Items Then UserForm1.Hide
End Sub