nemmi69
Well-known Member
- Joined
- Mar 15, 2012
- Messages
- 842
- Office Version
- 365
- 2019
- 2016
- 2013
- Platform
- 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 :-
Then I tried :-
<code>
</code></pre>
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></pre>