Add background colour to ListBox item(s) that have been selected...

Matty

Well-known Member
Joined
Feb 17, 2007
Messages
3,717
Hi Team,

I have a UserForm ListBox that is populated via a SQL connection. When a value is selected, a delimited string containing the selected values is created in a cell on a spare worksheet.

I would like the background colour of the ListBox item to be a different colour if it exists within the string held on the spare sheet mentioned above.

Can this be done?

Thanks,

Matty
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Hi Rory,

That does look more complicated than I was expecting/hoping!

Changing the background colour was just one option I was looking at. Is there an easier way/different method I could employ for identifying the ListBox items that exist on another sheet (i.e. the ones that have been selected already)?

Cheers,

Matty
 
Upvote 0
Depending on what you are doing, you could just pre-select them in the list?
 
Upvote 0
Hi again,

Here's a brief summary of the set up:


  • The UserForm contains two ListBoxes: the first ListBox contains hierarchy descriptions and the second ListBox contains the values that exist within the hierarchy selected.


  • The second ListBox is dynamically populated with data from SQL upon the user right clicking a hierarchy description from the first ListBox. They then have the ability to chose the values they wish from it.


  • Because the second ListBox is dynamically populated, once a user moves to choose values from another hierarchy description, it's not simple to see where previously applied filters exist.


  • To help identify them, I was wanting to highlight those hierarchy descriptions where underlying filters have already been applied.

The code itself works well (I think the right click functionality was one of Andy Pope's!); it's just the issue of highlighting that I want in order to finish things off.

Hope you can help.

Cheers,

Matty
 
Upvote 0
I think that would get pretty ugly with a listbox. A ListView could work, assuming all users would have it installed?
 
Upvote 0
The problem is that users are already familiar with the existing set up, so changing it is not really an option.

If colouring is a challenge, perhaps an additional character - say a "*" next to the hierarchy description - could work. Anything that indicates a filter has already been applied is all that's needed.

Cheers,

Matty
 
Upvote 0
You could do that, using whichever event you are currently using to populate the cells, or add the selections to a separate listbox.
 
Upvote 0
Hi,

Went down the route of a separate ListBox, which is working well.

Thanks for the suggestion!

Matty
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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