Wednesday, January 13, 2016

How to Add Item to ListBox in VBA (1)



CommandButon1 click:

1
2
3
4
5
Private Sub CommandButton1_Click()

ListBox1.AddItem "Sample Data"      'add item to list box

End Sub



1
2
3
4
5
6
7
8
Private Sub CommandButton1_Click()
Dim i As Integer

For i = 1 To 10
    ListBox1.AddItem "Sample Data" & i      'add item to list box
Next i

End Sub


Add data from cells

1
2
3
4
5
6
7
8
Private Sub CommandButton1_Click()
Dim i As Long

For i = 1 To Cells(Rows.Count, 1).End(xlUp).Row
    ListBox1.AddItem Cells(i, 1)                    'add item to list box
Next i

End Sub


Download File

Next (2)
Next (3)

No comments :

Post a Comment