Modify a list of labels on a worksheet if they are the ones selected

nemmi69

Well-known Member
Joined
Mar 15, 2012
Messages
842
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2013
Platform
  1. Windows
I have a number of labels on a worksheet that are to start with the background gray and if the user selects from a list of their names they will change to green. The problem I am having is that I can get the names of the labels but then cannot reference them to change their colour.

I tried :-

Code:
<code>Sub test1() Dim oLabel As OLEObject Dim LblCount As Integer  LblCount = 0 For Each oLabel In Worksheets("Sheet2").OLEObjects      Worksheets("Sheet2").Range("R" & LblCount + 1).Value = Right(oLabel.Name, Len(oLabel.Name) - 6)     'oLabel.BackColor = RGB(175, 175, 175)     Worksheets("Sheet2").OLEObject(oLabel).BackColor = RGB(175, 175, 175)     LblCount = LblCount + 1 Next oLabel  End Sub  Sub test2() Dim cCont As Control Dim LblCount As Integer  LblCount = 0 For Each cCont In Controls      If Left(oLabel.Name, 6) = "Label_" Then       Worksheets("Sheet2").Control(cCont).BackColor = RGB(175, 175, 175)     End If Next cCont End Sub

</code>

Then I tried :-
Code:
<code>Sub test1() Dim oLabel As OLEObject Dim LblCount As Integer  LblCount = 0 For Each oLabel In Worksheets("Sheet2").OLEObjects      Worksheets("Sheet2").Range("R" & LblCount + 1).Value = Right(oLabel.Name, Len(oLabel.Name) - 6)     Worksheets("Sheet2").OLEObjects(oLabel).Interior.ColorIndex = 15 'gray     'Worksheets("Sheet2").OLEObjects(oLabel).Interior.ColorIndex = 4 'green     LblCount = LblCount + 1 Next oLabel  End Sub</code>
<code>
</code></pre>
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Well this doesn't error but nor does it seem to do anything
Code:
 	Code:
 	
<code>Sub test1() Dim oLabel As OLEObject Dim LblCount As Integer  LblCount = 0 For Each oLabel In Worksheets("Sheet2").OLEObjects      Worksheets("Sheet2").Range("R" & LblCount + 1).Value = Right(oLabel.Name, Len(oLabel.Name) - 6)     Worksheets("Sheet2").OLEObjects(oLabel).Interior.ColorIndex = 15 'gray     'Worksheets("Sheet2").OLEObjects(oLabel.Name).Interior.ColorIndex = 4 'green     LblCount = LblCount + 1 Next oLabel  End Sub</code></pre>
 
Upvote 0

Forum statistics

Threads
1,203,384
Messages
6,055,115
Members
444,763
Latest member
Jaapaap

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