0
votes

I am running a UF which has 3 listboxes. I have BoxA_Click(), BoxB_Click subs for each, that select a cell on the a sheet when executed. If I click a value in BoxA, the macro executes and the cell is selected. Then if I click a value in BoxB, the macro executes and locates a different cell. The problem is, when I click back on BoxA, if I select the value that is already selected, then the BoxA_Click() macro will not execute, because I haven't technically changed the selection in that particular box.

My attempted solution was to create a frame, FrameMove, where I have put all 3 listboxes. I have tried to write something that will deselect the other 2 boxes when one box is clicked.

Private Sub BoxA_Click()
    GoToCell(BoxA.Value)
    Dim C As MSForms.Control
    For Each C In FrameMove.Controls
        If TypeOf C Is MSForms.ListBox Then 'C.ListIndex = -1 ???
    Next C
End Sub

I am currently looping through all controls within the frame, because I'm not sure how to loop through ListBoxes specifically. Is there a way I can make this work to deselect all other listboxes when one listbox is selected?

1
couldn't you just set the index to -1 at the end of the sub once you have moved to the cell? That would ensure that when you select the dropdown again, you would have to select the value. - Sorceri
That doesn't seem to do anything. I assume the macro executes at the click which would mean the actual selection happens immediately after, but still after the _Click effect has run, so it just stays selected. - teepee
Put your reset listbox code in Exit event (BoxA_Exit). - Jules

1 Answers

0
votes

Add a line of code to deselect the selected item at the end of each Listbox-click event.

BoxA.Selected(0) = False

And if the listbox is a multiple select, loop through them.

For i = 0 to BoxA.ListCount - 1
    BoxA.Selected(i) = False 
next i