2015-08-23 61 views
0

我一直在試圖改變下面的函數來計算,而不是按「標準」中定義的任何顏色vbRed:ALTER函數計算vbRed

Function CountCcolor(range_data As Range, criteria As Range) As Long 
    Dim datax As Range 
    Dim xcolor As Long 
xcolor = criteria.Interior.ColorIndex 
For Each datax In range_data 
    If datax.Interior.ColorIndex = xcolor Then 
     CountCcolor = CountCcolor + 1 
    End If 
Next datax 
End Function 

變化,如下面的一個失敗:

Function CountRed(range_data As Range) As Long 
    Dim datax As Range  

For Each datax In range_data 
    If datax.DisplayFormat.Interior.Color = vbRed Then 
     CountRed= CountRed+ 1 
    End If 
Next datax 
End Function 

回答

0

要讓您的變化起作用,請移除DisplayFormat

例如(這與DisplayFormat你的代碼中刪除):

Function CountRed(range_data As Range) As Long 
    Dim datax As Range 
    For Each datax In range_data 
     If datax.Interior.Color = vbRed Then 
      CountRed = CountRed + 1 
     End If 
    Next datax 
End Function 
+0

真棒!謝謝! – RTrain3k