Forum Discussion
Linking shapes color to a different cell color
Hi rgleong,
You can use VBA to achieve your goal.
Here is how you can do it (it is a concept, I haven't tested it)
1. Open the Visual Basic for Applications (VBA) Editor:
- Press "ALT + F11" in Excel to open the VBA Editor.
2. Insert a new module:
- In the VBA Editor, click on "Insert" in the menu, then click "Module."
3. Paste the VBA code:
- Copy and paste the following VBA code into the module you created:
Sub ChangeShapeOutlineColor()
Dim ws As Worksheet
Dim shapeCell As Range
Dim shape As Shape
Dim cellColor As Long
'Specify the worksheet containing the shapes and the table with cell colors
Set ws = ThisWorkbook.Worksheets("Sheet1")
'Loop through each shape
For Each shape In ws.Shapes
'Get the corresponding cell based on the shape name
Set shapeCell = ws.Range("A:A").Find(shape.Name)
If Not shapeCell Is Nothing Then
'Get the color of the corresponding cell
cellColor = shapeCell.Interior.Color
'Change the shape outline color to match the cell color
shape.Line.ForeColor.RGB = cellColor
End If
Next shape
End Sub
4. Run the macro:
- Close the VBA Editor and return to your Excel sheet.
- Press "ALT + F8" to open the "Macro" dialog box.
- Select the "ChangeShapeOutlineColor" macro from the list and click "Run."
The VBA macro loops through all shapes on the specified worksheet ("Sheet1" in this example). It matches each shape's name with the content in column A to find the corresponding cell. Then, it retrieves the cell's interior color and applies it to the shape's outline color
You can check these Microsoft Learn links if you want to learn some more about VBA and macros in Excel:
Getting started with VBA in Office | Microsoft Learn
Automate tasks with the Macro Recorder - Microsoft Support
Please click Mark as Best Response & Like if my post helped you to solve your issue.
This will help others to find the correct solution easily. It also closes the item.
If the post was useful in other ways, please consider giving it Like.
Kindest regards,
Leon Pavesic