List Box Woes

AlexanderBB

Well-known Member
Joined
Jul 1, 2009
Messages
2,058
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
It appears with MultiSelect=2 that the list box click event does not fire.
So I tried the Mouse Up event but Debug.Print ListBox2.Value there prints Null

Is there any way to get the list box value in this situation?

Thanks
 
Hmm the plot thickens. Under some circumstances

ClearBox ListBox1

Fails because ListBox1 is null. So if I pass in the name to the function, can I use the name rather than Controls(x) as I was doing?
 
Upvote 0

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
I can't imagine circumstances when you would try to clear a nonexistent listbox.

Some where in you change of statements, you'll have to test to see if the object you want to change (ListBox1) does exist. That checking can be done either before calling the clearing sub.

Code:
Dim ABox as MsForms.ListBox
' some code
If SomeCondition Then Set aBox = ListBox1
' more code

If Not aBox is Nothing then
    ClearBox aBox
End If
or as part of the Clearing Sub.

Code:
Sub ClearBox(aListBox as msForms.ListBox)
    If Not aListBox is Nothing then
        ' code
    End If
End Sub
 
Upvote 0
There's 3 listboxes and they all exist. But some may have nothing selected.
I don't know that so I unselect the two not currently in Mouse Up event..
For some reason Mike it only works with the code sending in the Listbox name.
Your last initially worked then "Could not set the Selected property. Unspecified error."
 
Upvote 0
That sounds like the code is being run when ListCount = 0

Perhaps
Code:
Sub UnSelectAll(aListBox as MsForms.ListBox)
    Dim i as Long
    With aListBox
        If 0< .ListCount Then
            For i = 0 to .ListCount - 1
                .Selected(i) = False
            Next i
        End If
    End With
End Sub
 
Upvote 0
Is it possible to upload a small 83KB xls file here?
Or can I post a dropbox link ?

I have this List box issue almost sorted but under one condition it fails.
I think Mike or others here may see what's wrong more easily than me trying to describe the
problem.

Thanks, Alex
 
Upvote 0

Forum statistics

Threads
1,223,609
Messages
6,173,331
Members
452,510
Latest member
RCan29

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top