2014-07-09 27 views
-4

我想幫助在Excel VBA功能改變行背景色爲灰色如果A1值+ D1值= C1值功能在Excel改變行背景色爲灰色如果A1值+ B1值= C1值

和變化它以紅色,如果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 
+1

你爲什麼不嘗試自己寫點東西?您在這裏完成的所有工作都是要求提供代碼併發佈一個非常不相關的功能。回顧你的努力並描述你遇到的任何問題。 –

+0

沒有VBA可以接受嗎? – pnuts

+0

@TimWilliams我現在無法訪問Excel來嘗試,因爲我在旅行回來之後旅行商務旅行,因爲我的時間測試代碼太短了,所以我想要一些代碼來節省我的時間..我希望你能幫助我我 – user3821236

回答

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 

這只是您必須做的一個示例/指南。希望它有幫助