Personally what I would do is rather than add an item to the ListBox itself, I would add the item to a worksheet somewhere and then link the RowSource property of the ListBox to the range on the worksheet where you add these items. As an example, let’s say you make Column A in Sheet1 your place for putting the list and you start with a heading in cell A1 (which won’t appear in the list):
To add an item to the list:
Code:
Private Sub CommandButton1_Click()
Dim Limit As Long
Limit = Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row + 1
Sheets("Sheet1").Cells(Limit, 1) = TextBox1.Value
ListBox1.RowSource = "Sheet1!A2:A" & Limit
End Sub
To remove an item from the list (note this is based on you selecting an item in the ListBox before pressing the button:
Code:
Private Sub CommandButton2_Click()
Dim DeleteRow As Long
Dim Limit As Long
DeleteRow = ListBox1.ListIndex + 2
If DeleteRow < 2 Then Exit Sub
Sheets("Sheet1").Rows(DeleteRow).Delete shift:=xlUp
Limit = Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row + 1
ListBox1.RowSource = "Sheet1!A2:A" & Limit
End Sub
Hope that helps!
