excel countif按樣式過濾

excel countif按樣式過濾

我有一個 Excel 電子表格,我正在嘗試根據應用於列中某些單元格的樣式來計算列中的行數。有沒有一種簡單的方法可以做到這一點?

答案1

不,不是真的。您可以使用 Visual Basic 存取儲存格格式設定屬性,但您在儲存格中鍵入的大多數內建函數都專注於儲存格內容,而不是格式設定。

如果您的樣式有不同的陰影顏色,那麼您可以使用以下方法。

步驟 1:將範​​圍轉換為列表,然後新增顯示 COUNT 的總計行

在此輸入影像描述

步驟 2:套用色彩濾鏡(應適用於 Excel 2007 及更高版本):

在此輸入影像描述

完成:COUNT 總計將顯示過濾後的行數。

在此輸入影像描述

答案2

您可以使用 VBA 來實現:

Function CountStyle(CellRange)
   Dim Item As Range, Total As Long
   For Each Item In CellRange
      ' Check to see if the cell is formatted as Style = "Neutral"
      If Item.Style = "Neutral" Then
         Total = Total + 1
      End If
   Next Item
   CountStyle = Total
End Function

取自這裡

  1. Alt+F11啟動 Visual Basic 編輯器。
  2. 插入 > 模組
  3. 插入上面的程式碼
  4. 前往 Excel 並選擇結果所在的儲存格。=CountStyle (B4:B23)

現在您已經計算了 style 的所有儲存格Neutral。我創建了三個函數:中立、好、壞。這看起來像:

Function CountStyleGood(CellRange)
   Dim Item As Range, Total As Long
   For Each Item In CellRange
      ' Check to see if the cell is formatted as Style = "Good"
      If Item.Style = "Good" Then
         Total = Total + 1
      End If
   Next Item
   CountStyleGood = Total
End Function

=CountStyleGood(B4:B23)你得到結果了。作為樣式的名稱,我使用了功能區中顯示的名稱。

相關內容