简体   繁体   中英

Excel - How to change a shape color based of the color of another cell

I am trying to change the color of multiple shapes based off a table on another tab. The table contains part, quadrant, shape name, and value (cell with specific color.) I am trying to tie the shape to the color by using shape name and range of where the color cell is but I get a sub/function not defined. The colors for the values in the table is based off a conditional format.

Sub Update()

Dim CellColor As Long
Dim ShapeColor As Variant

    CellColor = Worksheets("Sheet1").Range("D2").DisplayFormat.Interior.Color
    ShapeColor = Worksheets("Sheet1").Range("C2").Value
    Worksheets("main").Shapes(ShapeColor).Fill.ForeColor.RGB = CellColor

    Worksheets("main").Select
End Sub

在此处输入图像描述

在此处输入图像描述

Moving my comments to an answer:

  • Set should not be used here. Worksheet("main") is missing an s - Worksheets .
  • If conditional formatting, then you need to work with Worksheets("Sheet1").Range("D2").DisplayFormat.Interior.Color .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM