Hi, I developed a macro to change shapes colors based on the value of a cell. Originally I wrote this code
It was working well until I realized it was not changing the format of all shapes with the same name (it changes only one of them)
Doing a little of researching in blogs I think that the looping function can address what i am looking for.
I tried again with the following code (see changes in red).
But still not changing the format of the second shape with the same name.
Would somebody please provide advice / recommendations?
Thanks!
Rich (BB code):
ActiveSheet.Shapes.Range(Array("Col")).Select
If Range("D69") = "0" Then
Selection.ShapeRange.Fill.ForeColor.RGB = RGB(127, 127, 127)
ElseIf Range("D69") = "1" Then
Selection.ShapeRange.Fill.ForeColor.RGB = vbRed
ElseIf Range("D69") = "2" Then
Selection.ShapeRange.Fill.ForeColor.RGB = vbYellow
End If
It was working well until I realized it was not changing the format of all shapes with the same name (it changes only one of them)
Doing a little of researching in blogs I think that the looping function can address what i am looking for.
I tried again with the following code (see changes in red).
Rich (BB code):
For Each Shape In ActiveSheet.Shapes
If Shape.Name Like "Col" Then
ActiveSheet.Shapes.Range(Array("Col")).Select
If Range("D69") = "0" Then
Selection.ShapeRange.Fill.ForeColor.RGB = RGB(127, 127, 127)
ElseIf Range("D69") = "1" Then
Selection.ShapeRange.Fill.ForeColor.RGB = vbRed
ElseIf Range("D69") = "2" Then
Selection.ShapeRange.Fill.ForeColor.RGB = vbYellow
End If
End If
Next Shape
But still not changing the format of the second shape with the same name.
Would somebody please provide advice / recommendations?
Thanks!