Excel:获取单元格颜色

Can*_*ner 4 excel

1)如何使用Excel宏获取单元格的颜色?我无法使用此功能:

Sub BGCol(MRow As Integer, MCol As Integer)  
bgColor = Cells(MRow, MCol).Interior.ColorIndex  
End Sub
Run Code Online (Sandbox Code Playgroud)

2)在单元格x,y中我想要具有以下公式:

=BGCol(x,4)

那么如何获取当前行索引?

小智 8

Function GetColor(Mycell As Range)

    GetColor = Mycell.Interior.ColorIndex

End Function
Run Code Online (Sandbox Code Playgroud)

:::使用Formula :: = getcolor(x4)


Ekk*_*ner 6

你应该使用一个函数:

Function BGCol(MRow As Integer, MCol As Integer)  As Integer
   BGCol = Cells(MRow, MCol).Interior.ColorIndex  
End Function
Run Code Online (Sandbox Code Playgroud)