下面是UDF,它将给你电池填写彩色(包括从有条件格式上填充的颜色),而没有这个编号#VALUE差错<<>>>。
Option Explicit
Public Function CellFillColor(target As Range, Optional returnFormat As String = "IDX") As Variant
Dim retArray()
Dim rowCounter As Long
Dim colCounter As Long
Dim colorValue As Long
Application.Volatile
If TypeName(target) = "Range" Then
ReDim retArray(target.Rows.Count - 1, target.Columns.Count - 1)
For rowCounter = 0 To target.Rows.Count - 1
For colCounter = 0 To target.Columns.Count - 1
colorValue = Evaluate("useDF(" & target.Cells(rowCounter + 1, colCounter + 1).Address & ")")
Select Case UCase(returnFormat)
Case "RGB":
retArray(rowCounter, colCounter) = _
Format((colorValue Mod 256), "00") & ", " & _
Format(((colorValue 256) Mod 256), "00") & ", " & _
Format((colorValue 65536), "00")
Case "HEX":
retArray(rowCounter, colCounter) = _
"#" & _
Format(Hex(colorValue Mod 256), "00") & _
Format(Hex((colorValue 256) Mod 256), "00") & _
Format(Hex((colorValue 65536)), "00")
Case "IDX": retArray(rowCounter, colCounter) = colorValue
Case Else: retArray(rowCounter, colCounter) = colorValue
End Select
Next colCounter
Next rowCounter
CellFillColor = retArray IIf(target.CountLarge = 1, retArray(0, 0), retArray)
End If
End Function
Private Function useDF(ByVal target As Range) As Variant
useDF = target.DisplayFormat.Interior.Color
End Function
in Immediate Window
Range("G16").Interior.Color=13551615<-IDX value
另见我的。
它基于Jaafar Tribak。 s 代码,他在。
I hope this helps.
Feel free to take it apart and/or rearrange it as above code was written for giving more choices to the user thereby making it (unnecessarily?) longer.