Search code examples
vbaexcellistboxcommandbutton

CommandButton to add from listbox to sheet


hello i search a lot of information in internet but i can not get it work .I tray to add the search results from listbox in a sheet number the sheet name is (Tabelle1 ) listbox name is (lsbWarenausgang) and the CommandButton name is (CommandButton3)


Solution

  • Assuming you want pass the value to the cell C1:

    Private Sub CommandButton3_Click()
    
        Worksheets("Tabelle1").Range("C1").Value = lsbWarenausgang.Value
    
    End Sub
    

    For multi-columns ListBox:

    Private Sub CommandButton3_Click()
    Dim i As Integer
    Dim k As Integer
    With Me.lsbWarenausgang
       For k = 0 To .ListCount - 1
          If .Selected(k) = True Then
          For i = 1 To 5
             Worksheets("Tabelle1").Cells(i, 1) = Me.lsbWarenausgang.List(k, i - 1)
           Next i
          End If
       Next k
    End With
    End Sub