2008-09-08 136 views

回答

8

Excel無法通過它的內置函數來收集該屬性。如果你願意使用一些VB,所有的顏色相關的問題都在這裏找到答案:

http://www.cpearson.com/excel/colors.aspx

例形成的部位:

的SumColor功能是基於顏色的 模擬SUM和SUMIF 函數。它可以讓你對他們 顏色索引進行檢查和 細胞,其值是 概括的範圍的範圍內指定 不同的範圍。如果這兩個範圍是 相同,則該函數會將顏色與指定的 值相匹配的單元格 相加。例如,以下 公式將B11:B17 中的值填充顏色爲紅色。

=SUMCOLOR(B11:B17,B11:B17,3,FALSE)

5

在工作表式,=CELL("color",D3)返回1如果細胞與彩色負值格式化(否則返回0)。

你可以用一點VBA解決這個問題。插入此成VBA代碼模塊:

Function CellColor(xlRange As Excel.Range) 
    CellColor = xlRange.Cells(1, 1).Interior.ColorIndex 
End Function 

然後使用功能=CellColor(D3)顯示我剛剛創建這個D3的的.ColorIndex

+0

我似乎無法得到這個工作。當有6個顏色的單元格時,顏色索引出現在55。 – FortunateDuke 2008-09-08 22:57:27

3

,它看起來更容易。你得到這2個功能:

=GetColorIndex(E5) <- returns color number for the cell 
從(小區)

=CountColorIndexInRange(C7:C24,14) <- returns count of cells C7:C24 with color 14 

(單元格區域,色號要算)

例子顯示了細胞的百分比與顏色14

=ROUND(CountColorIndexInRange(C7:C24,14)/18, 4) 

在模塊中創建這2個VBA函數(點擊Alt-F11)

打開文件夾。在模塊1

雙擊只需粘貼這段文字下面,然後關閉模塊窗口(它必須保存它,然後):

Function GetColorIndex(Cell As Range) 
    GetColorIndex = Cell.Interior.ColorIndex 
End Function 

Function CountColorIndexInRange(Rng As Range, TestColor As Long) 
    Dim cnt 
    Dim cl As Range 
    cnt = 0 

    For Each cl In Rng 
    If GetColorIndex(cl) = TestColor Then 
     Rem Debug.Print ">" & TestColor & "<" 
     cnt = cnt + 1 
    End If 
    Next 

    CountColorIndexInRange = cnt 

End Function 
2

我需要完全解決相同的任務。我用不同的背景顏色對不同的部分進行了視覺分割。使用互聯網搜索我已經找到這個頁面https://support.microsoft.com/kb/2815384。不幸的是,它並不能解決問題,因爲ColorIndex引用了一些不可預知的值,所以如果某些單元格具有一種顏色的細微差別(例如顏色亮度的不同值),則建議的函數會對它們進行計數。下面的解決方案是我的修復:

Function CountBgColor(range As range, criteria As range) As Long 
    Dim cell As range 
    Dim color As Long 
    color = criteria.Interior.color 
    For Each cell In range 
     If cell.Interior.color = color Then 
      CountBgColor = CountBgColor + 1 
     End If 
    Next cell 
End Function 
0

是的VBA是要走的路。

但是,如果您不需要具有使用特定顏色自動計數/更新單元格數量的公式的單元格,則可以使用「查找和替換」功能並格式化單元格有適當的顏色填充。

點擊「全部查找」會顯示對話框左下方的單元格總數。

enter image description here

這將成爲,如果你的搜索範圍是巨大的特別有用。 VBA腳本將非常慢,但「查找和替換」功能仍然非常快。

相關問題