disable entry on listbox

  • Thread starter Thread starter Smallweed
  • Start date Start date
S

Smallweed

Can I selectively disable an individual entry on a multiselect listbox in a
userform? If so, how?

Thanks
 
How about just not including it in the listbox to start--or removing it when it
shouldn't be selected?

Or even just ignore it if it is selected?

But if you want...

Option Explicit
Dim BlkProc As Boolean
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub CommandButton2_Click()
Dim iCtr As Long
With Me.ListBox1
For iCtr = 0 To .ListCount - 1
If .Selected(iCtr) = True Then
MsgBox iCtr & "--" & .List(iCtr)
End If
Next iCtr
End With
End Sub
Private Sub ListBox1_Change()

Dim ItemToBeAvoided As Long

If BlkProc = True Then
Exit Sub
End If

ItemToBeAvoided = 2 'third item (0 based)

If Me.ListBox1.Selected(ItemToBeAvoided) = True Then
BlkProc = True
Me.ListBox1.Selected(ItemToBeAvoided) = False
BlkProc = False
End If

End Sub
Private Sub UserForm_Initialize()
Dim iCtr As Long
With Me.ListBox1
.MultiSelect = fmMultiSelectMulti
For iCtr = 1 To 5
.AddItem "A" & iCtr
Next iCtr
End With
End Sub
 
Back
Top