Userform listbox row selection fails

Hilarys

New Member
Joined
Nov 1, 2021
Messages
10
Office Version
  1. 2019
Platform
  1. Windows
I have a UserForm which includes two ListBoxes on one page of a MultiPage. The two ListBoxes are identical apart from the ControlSource and the position on the form. In one of the ListBoxes, a mouse click on a populated row highlights the row and writes the bound column data to the ControlSource, i.e. as expected. In the other ListBoxe, a mouse click causes the bound column data to flash in the ControlSource, but it then disappears, and no highlighting occurs, so row selection is impossible. What am I doing wrong?
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
I suspect that writing to the worksheet is causing a recalculation of the rowsource for the control, which then clears the selection. I recommend not binding the controls directly to ranges for this reason.
 
Upvote 0
I suspect that writing to the worksheet is causing a recalculation of the rowsource for the control, which then clears the selection. I recommend not binding the controls directly to ranges for this reason.
OK, but there are no formulae that use the ControlSource. The RowSource was set from code. And why does it work as it should for one ListBox but not the other?
 
Upvote 0
What is the rowsource set to?

It's very hard to diagnose things like this without the workbook, but the most likely causes are the ones I mentioned, or code that is being triggered when you select an item in the listbox.
 
Upvote 0
OK. There's only one workbook involved here, and the two ListBoxes each display a (separate) portion of one worksheet, which is not the worksheet referenced in the ControlSource of either. There is no code associated with the selection of a row (other than the MS code to highlight the row and set the ControlSource value). The workbook in question contains proprietary data, but I'll try to build a beige version that misbehaves in the same way. Thanks for the suggestions.
 
Upvote 0
It's most likely the RowSource that is the issue, not the ControlSource.
 
Upvote 0
It's most likely the RowSource that is the issue, not the ControlSource.
I haven't got a beige version yet, but I did notice that setting the RowSource uses identical code for the two ListBoxes. What's going on is that a list of data values is being sorted into two based on a criterion entered by the user. The two resulting lists are sorted into alpha order and then displayed in the form. There's one block of code that writes the two lists, then sorts them and then sets the RowSource. Control is then passed back to the user.
 
Upvote 0
Are both rowsources set to static range addresses?
 
Upvote 0
The code is:

mystring = "Display!CG2:CI" & cmy + 10
msincs.MultiPage1.Pages(4).Controls("ctomsexist").RowSource = mystring
mystring = "Display!CM2:CO" & cmn + 10
msincs.MultiPage1.Pages(4).Controls("ctomscand").RowSource = mystring

where cmy and cmn are both integers. "ctomsexist" and "ctomscand" are the ListBoxes, of course.
 
Upvote 0
I think I'd have to see a representative workbook then. Something must be resetting the listbox, from what you describe.
 
Upvote 0

Forum statistics

Threads
1,215,513
Messages
6,125,253
Members
449,219
Latest member
daynle

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