![](/img/trans.png)
[英]Excel - Highlight a cell using conditional formatting based on other cells that are highlighted
[英]How to highlight a cell in Excel using conditional if?
如何有條件地為單元格分配顏色?
我有以下函數 ,應該根據if語句為單元格分配不同的顏色:
Function .....
..........
If (IsNumeric(x) Then
.Color = 65344 // does not work
Else
...........
End If
End Function
如何以正確的方式做到這一點?
我不確定您在這里使用什么顏色,因為65344不是十六進制值,但是您可以像這樣使用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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.