如果A1值+ D1值= C1值
,我需要excel中的VBA函数帮助将行BackColor更改为灰色如果A1值+ D1值= 0.9 * C1值
,则将其更改为红色我希望它像这段代码一样工作得非常好
Function CountCellsByColor(rData As Range, cellRefColor As Range) As Long
Dim indRefColor As Long
Dim cellCurrent As Range
Dim cntRes As Long
Application.Volatile
cntRes = 0
indRefColor = cellRefColor.Cells(1, 1).Interior.Color
For Each cellCurrent In rData
If indRefColor = cellCurrent.Interior.Color Then
cntRes = cntRes + 1
End If
Next cellCurrent
CountCellsByColor = cntRes
End Function
答案 0 :(得分:0)
我没有得到你的代码,你需要做的就是这样。
if range("a1").value + range("d1").value = range("c1").value then
Range('"the row you want to change"').interior.color= 'lookforgreycolorrgb'
else if range("a1").value + range("d1").value = (.9*range("c1").value) then
Range('"the row you want to change"').interior.color= vbRed
end if
这只是你必须做的事情的一个例子/指南。希望它有所帮助