I have multiple shapes linked to cell as text box. When I select say Cell A1 rectangle 20 which is linked to it will be filled with green color. However, I have more than 200 rectangles and I want this process to be automatic without individually typing a code for each shape linked to cell. Each text in every rectangle is linked to any cell with similar text in Column A. That means if one of the cell clicked in column A has the same text inside one of the shapes, then that corresponding shape will be filled with green color. Is it possible to create a general code based on this correspondence? Thank you.
The following is my crude vba code.
The following is my crude vba code.
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'Fill previous shapes with white color and fill "rectangle 1" with green color
If Target.Row = 1 And Target.Column = 1 Then
ActiveSheet.Shapes.SelectAll
With Selection.ShapeRange.Fill
.ForeColor.RGB = vbWhite
ActiveCell.Select
ActiveSheet.Shapes("Rectangle 1").Fill.ForeColor.RGB = vbGreen
End With
End If
'Fill previous shapes with white color and fill "rectangle 2" with green color
If Target.Row = 2 And Target.Column = 1 Then
ActiveSheet.Shapes.SelectAll
With Selection.ShapeRange.Fill
.ForeColor.RGB = vbWhite
ActiveCell.Select
ActiveSheet.Shapes("Rectangle 2").Fill.ForeColor.RGB = vbGreen
End With
End If
End Sub
Last edited by a moderator: