Excel: set cell color to another

How to determine the cell color equal to another, for example: A4 then C2 is blue. A2 then C2 orange is orange. enter image description here

+2
source share
2 answers

There is no excel formula to get the color of the cell, and no to set the color of the other.

However, you can make a function to get the color of a specific cell - or, as in my example, the color of the function's 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 may think, okay, then I change this, just to set the color too. But no - that doesn't work. To change the color of the cells, you will need to use the Worksheet_Change event and set each cell to a long value inside them as a color.

 Target.Interior.Color = Target.Value 

There would be a line for this when using Worksheet_Change .

Of course you can use ColorIndex - just adapt accordingly.

+1
source

here is some C # code, maybe it can help 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; 
0
source

Source: https://habr.com/ru/post/1272538/


All Articles