2

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. enter image description here

Regis Santos
  • 3,469
  • 8
  • 43
  • 65
  • You can't alter the colour of the cell with a formula. You can get the colour of another cell by writing your own VBA function but if you want to change the colour you have to use a macro which cannot be called like a function. All a function can do is return a value, it cannot change any worksheet properties such as formatting. – Dan Nov 13 '12 at 14:29

2 Answers2

1

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.

Jook
  • 4,564
  • 3
  • 26
  • 53
0

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;
Sylca
  • 2,523
  • 4
  • 31
  • 51