ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   disable entry on listbox (https://www.excelbanter.com/excel-programming/418882-disable-entry-listbox.html)

Smallweed

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

Thanks

Incidental

disable entry on listbox
 
Hi Smallweed

The code below should sort of do what you want it will check if your
item has been clicked and if so it will deselect it.

Private Sub ListBox1_MouseUp(ByVal Button As Integer, ByVal Shift As
Integer, ByVal X As Single, ByVal Y As Single)

If ListBox1.Selected(3) = True Then

ListBox1.Selected(3) = False

End If

End Sub

Hope this helps

Steve

Dave Peterson

disable entry on listbox
 
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

Smallweed wrote:

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

Thanks


--

Dave Peterson


All times are GMT +1. The time now is 10:01 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com