求教

请教 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