Consulting

Results 1 to 2 of 2

Thread: repeated user input

  1. #1
    VBAX Regular
    Joined
    Sep 2012
    Posts
    11
    Location

    repeated user input

    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:[vba]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[/vba]
    Attached Files Attached Files

  2. #2
    VBAX Mentor
    Joined
    Jul 2012
    Posts
    398
    Location
    you don't need loop
    [vba]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[/vba]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •