Assuming listbox is on a userform
Option Explicit
Private mUpdatingList As Boolean
Private Sub UserForm_Initialize()
mUpdatingList = True
With ListBox1
.MultiSelect = fmMultiSelectMulti
.ListStyle = fmListStyleOption
.List = Array("Select All", 1, 2, 3, 4, 5)
End With
mUpdatingList = False
End Sub
Private Sub ListBox1_Change()
Dim a As Long
Dim state As Long
If mUpdatingList Then Exit Sub
If ListBox1.ListIndex = 0 Then
mUpdatingList = True
state = ListBox1.Selected(0)
For a = 1 To ListBox1.ListCount - 1
ListBox1.Selected(a) = state
Next
If state Then
ListBox1.List(0) = "Deselect All"
Else
ListBox1.List(0) = "Select All"
End If
mUpdatingList = False
End If
End Sub
Bookmarks