Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel: Get cell color

Tags:

excel

1) How do I get the color of a cell using an Excel Macro? I couldn't get this function work:

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

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

=BGCol(x,4)

So how do I get the current row index?

like image 598
Caner Avatar asked Dec 09 '22 10:12

Caner


2 Answers

Function GetColor(Mycell As Range)

    GetColor = Mycell.Interior.ColorIndex

End Function

:::Use Formula:: =getcolor(x4)

like image 63
Brandon Avatar answered Dec 21 '22 23:12

Brandon


You should use a Function:

Function BGCol(MRow As Integer, MCol As Integer)  As Integer
   BGCol = Cells(MRow, MCol).Interior.ColorIndex  
End Function
like image 39
Ekkehard.Horner Avatar answered Dec 22 '22 01:12

Ekkehard.Horner