Consulting

Results 1 to 4 of 4

Thread: ListBox mirror TextBox and Copy to Excel Table

  1. #1

    ListBox mirror TextBox and Copy to Excel Table

    Hello Everyone,

    I’m hoping someone can help me as I’m having a hard time figuring this out. What I’d like to do:
    As I type a number in the textbox, I’d like the amount to appear alongside in the listbox .
    When I click on the transfer button, I’d like the listbox values to populate my table on sheet 1. Below is the code, I’m also including the workbook for clarity. Thank you in advance.

    Private Sub TransferData_Click()
        Dim i As Long
        Dim ws As Worksheet
        Dim nextAvailableRow As Long
        'check if listbox is empty
      If Listbox1.ListCount = 0 Then
            MsgBox "Nothing Has Been Added", vbInformation, "ListBox Empty"
            Exit Sub
        End If
        Set ws = Sheets("Sheet2")
        For i = 0 To Listbox1.ListCount - 1
            nextAvailableRow = ws.Range("B" & Rows.Count).End(xlUp).Row + 1
            ws.Range("b" & nextAvailableRow) = Listbox1.Column(0, i)
            ws.Range("c" & nextAvailableRow) = Listbox1.Column(1, i)
            ws.Range("d" & nextAvailableRow) = Listbox1.Column(2, i)
        Next i
        Listbox1.Clear
    End Sub
     
    Private Sub UserForm_Activate()
    For i = 1 To 5
        Me.Controls("Label" & i).Caption = Me.Controls("Label" & i).Name
    Next i
    End Sub
     
    Sub getSum()
    On Error Resume Next
    For i = 1 To 5
        If Me.Controls("Textbox" & i) <> Empty Then
            cntr = cntr
        End If
      cVal = cVal + CDbl(Me.Controls("Textbox" & i))
    Next i
     Me.TextBox11 = cVal + cntr
    End Sub
     
    Private Sub TextBox1_Change()
    getSum
      Me.Listbox1.AddItem
      Me.Listbox1.List(pos, 0) = Me.TextBox1
    End Sub
    
    Private Sub TextBox2_Change()
    getSum
      Me.Listbox1.AddItem
      Me.Listbox1.List(pos, 1) = Me.TextBox2
    End Sub
    
    Private Sub TextBox3_Change()
    getSum
    End Sub
     
    Private Sub TextBox4_Change()
    getSum
    End Sub
    
    Private Sub TextBox5_Change()
    getSum
    End Sub
    
    Private Sub TextBox6_Change()
    getSum
    End Sub
    
    Private Sub TextBox7_Change()
    getSum
    End Sub
    
    Private Sub TextBox8_Change()
    getSum
    End Sub
    
    Private Sub TextBox9_Change()
    getSum
    End Sub
    
    Private Sub TextBox10_Change()
    getSum
    End Sub
    Attached Files Attached Files

  2. #2
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,642
    You don't need the listbox.
    See the attachment
    Attached Files Attached Files

  3. #3
    yes, it works and thank you but that is not the objective i was going for. i need the table as it will later contain other info and i need it in sheet1, not sheet sheet2

  4. #4
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,642
    You have my permission to adapt the code.

    And please do not contradict your own code:
    ws = Sheets("Sheet2")

Posting Permissions

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