Reputation: 3749
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.
Upvotes: 2
Views: 14848
Reputation: 2545
here is some C# code, maybe it could be helpful to you:
xlSheet.Range["A10", "A10"].Interior.Color = ColorTranslator.ToOle(System.Drawing.Color.Cyan);
xlSheet.Range["C10", "C10"].Interior.Color = xlSheet.Range["A10", "A10"].Interior.Color;
Upvotes: 0
Reputation: 4682
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.
Upvotes: 1