如何在Excel中使用条件突出显示单元格?
我怎样才能有条件地分配颜色的细胞?
我有以下function ,应根据if语句为单元格分配不同的颜色:
Function ..... .......... If (IsNumeric(x) Then .Color = 65344 // does not work Else ........... End If End Function
如何以正确的方式做到这一点?
我不确定你在这里使用的是什么颜色,因为65344不是hex值,但是你可以像这样使用RGB:
Function ..... .......... Dim c As Range Dim report As Worksheet Set report = Excel.ActiveSheet Set c = report.Cells(1, 1) If IsNumeric(c.Value) Then c.Interior.Color = RGB(110, 110, 100) End If End Function
这是一个更好的例子,可能有帮助。 (这是免费的,所以仔细检查它的语法错误)
Sub changeColor() Dim report as Worksheet set report = Excel.ActiveSheet dim i as integer for i = 0 to 100 if IsNumeric(report.cells(i,1).value) then report.cells(i,1).interior.color = rgb(220,230,241) else report.cells(i,1).interior.color = xlNone end if next i end sub