簡體   English   中英

計算具有特定顏色和文本的單元格

[英]Count cells with specific color and text

我能夠讓這個 function 正常工作。 我嘗試過添加另一個變量但失敗了。

我想計算顏色和文本是否與某個范圍內的特定變量匹配。

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 CountCcolor(range_data As Range, criteria As Range) As Long
    Dim datax As Range
    Dim xcolor As Long
    Dim xtext as String

xcolor = criteria.Interior.ColorIndex
xtext = criteria.value2

For Each datax In range_data
    If datax.Interior.ColorIndex = xcolor and datax.value2 = xtext Then
        CountCcolor = CountCcolor + 1
    End If
Next datax
End Function

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM