Excel:将单元格的颜色设置为另一个单元格的颜色 [英] Excel: setting the color of a cell to another
问题描述
如何确定一个单元格的颜色等于另一个单元格,例如:
A4然后C2是青色青色。
A2则C2橙色橙色。
然而,你可以创建一个函数来获取特定单元格的颜色,或者像在我的例子中那样,调用函数单元格的颜色:
<$ p
$如果TypeName(Application.Caller)=Range则
Set rng = Application .Caller
End If
GetColor = rng.Cells.Interior.Color
End Function
现在你可以认为,好的,我修改这个,只是设置颜色。但是没有 - 不这样工作。为了更改单元格颜色,您必须使用 Worksheet_Change
事件,并将每个单元格设置为其中的长整型值作为其颜色。
Target.Interior.Color = Target.Value
$ b $当用 Worksheet_Change
。
你可以使用 ColorIndex
- 只需做相应的调整即可。
How do I determine the color of a cell equal to another, example: A4 is then C2 is cyan color cyan. A2 is then C2 orange color is orange.
There is no excel-formula to get you the color of a cell, nor is there one, to set the color of a different one.
However, you can make a function to get the color of a specific cell - or, like in my example, the color of the function-calling cell:
Public Function GetColor()
Dim rng As Range
If TypeName(Application.Caller) = "Range" Then
Set rng = Application.Caller
End If
GetColor = rng.Cells.Interior.Color
End Function
Now you might, think, ok then I modify this, just to SET the color too. But no - does not work that way. In order to change a cells color, you would have to use Worksheet_Change
event and setup each cell to the long value inside them as their color.
Target.Interior.Color = Target.Value
Would be the line for that, when using Worksheet_Change
.
You can of course use ColorIndex
as well - just adapt accordingly.
这篇关于Excel:将单元格的颜色设置为另一个单元格的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!