Excel: get cell color

1) How to get cell color using Excel macro? I could not get this function to work:

Sub BGCol(MRow As Integer, MCol As Integer) bgColor = Cells(MRow, MCol).Interior.ColorIndex End Sub 

2) In cell x, y I want to have the following formula:

=BGCol(x,4)

So how do I get the current row index?

+4
source share
2 answers

You should use the function:

 Function BGCol(MRow As Integer, MCol As Integer) As Integer BGCol = Cells(MRow, MCol).Interior.ColorIndex End Function 
+6
source
 Function GetColor(Mycell As Range) GetColor = Mycell.Interior.ColorIndex End Function 

: Use the formula :: = GetColor (x4)

+8
source

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


All Articles