CommandButton从列表框添加到工作表

时间:2016-08-04 08:23:07

标签: excel vba excel-vba listbox commandbutton

你好我在互联网上搜索了很多信息,但是我无法让它工作。我的托盘将列表框中的搜索结果添加到工作表编号中,工作表名称是(Tabelle1)列表框名称是(lsbWarenausgang)和CommandButton名称是(CommandButton3)

1 个答案:

答案 0 :(得分:1)

假设您想将值传递给单元格C1:

Private Sub CommandButton3_Click()

    Worksheets("Tabelle1").Range("C1").Value = lsbWarenausgang.Value

End Sub

对于多列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