Shift click to trap selection in a ComboBox for selection deletion

Mike_Excel2003

New Member
Joined
Jul 20, 2011
Messages
6
Hi.
I want a user to be able to click on any value in a combobox whle holding down the Shift key, and have the code remove that value (ultimately, with a cautionaty prompt to do so).

After, have all the remaining elements stay in the combobox and display the first element as the 'header' of that combobox.

The errors I am getting just seem random, unpredictible and illogical - almost human like!!. It's unreal, even to the point a msgbox is essential to force a refresh of an internal property.

I've been working on this for days, and have exhausted my ideas on how to get it working. Please, be so kind as to show me the way.

Thanks.
Mike.

Code:
Private Sub ComboBox2_MouseDown _
(ByVal Button As Integer, _
ByVal Shift As Integer, _
ByVal X As Single, _
ByVal Y As Single)

Dim entry_to_be_deleted As String

'
'
' Note: Runs whenever left mouse click selects ComboBox
' or mouse is used to click (and deselect) outside the ComboBox
'
' How to get shift+select
' wroking in a ComboBox came from Michael S. Meyers-Jouan and Johan deWispelaere
' http://visualbasic.ittoolbox.com/groups/technical-functional/vb-vba-l/distinguish-between-click-and-shiftclick-in-vba-excel-1820618
'
If Shift Then
MsgBox "" ' This seems essential to force ComboBox2.ListIndex _
          ' to refresh to take on the index of the selected _
            ' element in the Combo box
ComboBox2.RemoveItem ComboBox2.ListIndex ' this sometimes throws up an error (is it because ListIndex sometimes = -1???}
ComboBox2.Text = ComboBox2.List(0) ' I want to have an element show in the header of the ComboBox.
                                    ' although having it be the element one above the element just deleted is much
                                    ' is more preferred.
' sometimes get the combo box looking totally empty, other times not.
End If


End Sub
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
I should have added the ComboBox is a 'Control Box' ComboBox,
i.e. NOT a forms based box, although if any suggested code could be suggested for the Forms based box too, I'd be very grateful indeed!
Thanks.
Mike.
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,345
Members
452,907
Latest member
Roland Deschain

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