簡體   English   中英

計算具有特定填充顏色和像元值的像元數

[英]Count the number of cells with both specific fill color and cell value

我在下面使用代碼,但無法正常工作。

Function CountColorValue(CountRange As Range, CountColor As Range, CountVAlue As Range)

  Dim numbers As Long
  Dim Cell As Range

  Set rCell = CountRange

  For Each rCell In CountRange
    If rCell.Interior.ColorIndex = Color Then
      If rCell.Value = Value Then
        numbers = numbers + 1
      End If

      GetColorCount = TotalCount

End Function

謙虛地建議您進入VBE的“工具”►“選項”,然后在“編輯器”屬性頁上,在“ 要求變量聲明”旁邊打勾。 這將幫助您避免拼寫錯誤或完全省略所使用變量的名稱。

Function CountColorValue(CountRange As Range, CountColor As Range, CountValue As Range)

    Dim iNumbers As Long
    Dim rCell As Range

    For Each rCell In CountRange
        If rCell.Interior.ColorIndex = CountColor.Interior.ColorIndex Then
            If rCell.Value2 = CountValue.Value2 Then
                iNumbers = iNumbers + 1
            End If
        End If
    Next rCell

    CountColorValue = iNumbers

End Function

似乎您正在嘗試將兩個緊密相關的功能融合在一起,但是如果沒有正確的變量聲明和賦值,就無法在一個功能中使用另一個功能。

暫無
暫無

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

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