Change the backcolor of listbox using VBA.

atf32

Board Regular
Joined
Apr 13, 2011
Messages
157
Need code for changing the backcolor of a listbox (on the surface of excel), through VBA (excel 2003). The color is "&H0050D092&" :confused:....."yes" need to use this color.
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Hello atf32,

There are 2 types of ListBox controls: Forms and ActiveX (Control Tollbox). With the Forms control you can not change the back color. With the ActiveX control you can by setting the BackColor property.

ActiveX Control on a Worksheet Example
Code:
    ActiveSheet.OLEObjects("ListBox1").Object.BackColor = &H50D092

EDIT: You can replace "ActiveSheet" with the worksheet that ListBox is on like, "Worksheets("Sheet1").OLEObjects("ListBox1").Object.BackColor = &H50D092
 
Last edited:
Upvote 0
This helped....Have another related question.......

I have two lisbox. If user select a certain value in listbox1, then listbox2 gets turned to a certain color. I have this down. But when the backcolor for listbox2 is changed, the selected value in listbox2 is lost. Is it possible to keep it?:confused:
 
Upvote 0
Hello atf32,

After changing the color of the second List Box, add DoEvents immediately after it. This will cause the List Box to be repainted on the Worksheet.
 
Upvote 0
Code:
With ListBox2
    IndexMemory = .ListIndex
    .BackColor = newColor
    .ListIndex = IndexMemory
End with
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,729
Members
452,939
Latest member
WCrawford

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