Excel VBA ListBox Functions with Examples

Опубликовано: 14 Январь 2025
на канале: EXCEL'N CRICKET (Jithin R Trivandrum)
61
3

Excel VBA ListBox Functions. How to input our items inside a list box and how to display the selected items in our sheets.

Private Sub ListBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 13 Then
For i = 0 To ListBox1.ListCount - 1
x = sheets("Master").Range("C" & Rows.Count).End(xlUp).Row + 1
If Me.ListBox1.Selected(i) Then
sheets("Master").Range("C" & x).Value = Me.ListBox1.List(i, 0)
End If
Next
End If
End Sub
Private Sub UserForm_Initialize()
x = sheets("Master").Range("A" & Rows.Count).End(xlUp).Row
Me.ListBox1.List = sheets("Master").Range("A2:A" & x).Value
End Sub