求教

請教 excel,如圖中"小計"欄中的 I37,是前4個變了藍色格的數量,現在我是手動輸入的,有沒有程式當前面方格轉了指定顏色便會自動+1,例如: 20號方格(手動)轉了藍色,小計欄 I40 便會變成 1,21號變咗藍色,I40 會 +1=2,如此類推到25號,謝謝解答!

EX.jpg

.

你需要使用VBA Function
  1. Function CountBlueCells(rng As Range) As Long
  2.     Dim cell As Range
  3.     Dim count As Long
  4.     count = 0
  5.     For Each cell In rng
  6.         If cell.Interior.Color = RGB(0, 0, 255) Then ' Pure blue
  7.             count = count + 1
  8.         End If
  9.     Next cell
  10.     CountBlueCells = count
  11. End Function
複製代碼
然後在 I40 輸入公式 =CountBlueCells(C40:H40)

TOP

謝謝,我試試先

TOP