Can't use the CTRL key on Extended list box

azizrasul

Well-known Member
Joined
Jul 7, 2003
Messages
1,304
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
List box with Multiselect set to Extended.

I have the following code on the click event of a list box.

Code:
    Dim ctl As Control
    Dim x As Variant

    Set ctl = Me!lstLandParcelReminders
    
    For Each x In ctl.ItemsSelected
        If ctl.Selected(x) = -1 Then
            ctl.Selected(x) = True
        Else
            ctl.Selected(x) = False
        End If
        Me.Refresh
    Next x
     
    Set ctl = Nothing

How do I amend the above code so that when pressing the CTRL key, the correct item are selected\deselected e.g. when I have 3 items all selected on a list box and press CTRL on the middle item, the bottom 2 items deselect rather than just the middle one.
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Fluff, I did not create a duplicate thread, I simply edited my original thread so don't know how the duplicate got created!
 
Last edited:
Upvote 0
Fluff, I did not create a duplicate thread, I simply edited my original thread so don't know how the duplicate got created!

Couldn't reproduce the problem.

Is that listbox on a userform or on a worksheet ?
 
Upvote 0
Userform.

Changed Me.Refresh to Me.Requery and it worked.
 
Upvote 0

Forum statistics

Threads
1,223,943
Messages
6,175,552
Members
452,652
Latest member
eduedu

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