Board logo

標題: [發問] 數儲存格顏色數目。 [打印本頁]

作者: stephenlee    時間: 2020-5-23 16:40     標題: 數儲存格顏色數目。

我要在 A欄至J欄中數有顏色的儲存格數目。(只有一款黃色)
當按下按鈕後,便會提示 有多少個數目。
在網上找到以下資料,但是固定了在第二欄,請問如何做到 由A欄至J欄, 找到有顏色的儲存格後,將數目用msgbox 提示出來。謝謝


Sub test()
Dim sum As Long, Count As Long


sum = 0
Count = 0

For i = 1 To 10

If Cells(i, 2).Interior.ColorIndex = 6 Then

sum = sum + Cells(i, 2).Value

Count = Count + 1

End If

Next i


MsgBox Count & "  different Finds"

End sub
作者: 微風    時間: 2020-5-23 19:00

  1. Sub test()
  2. Dim sum As Long, Count As Long


  3. sum = 0
  4. Count = 0

  5. For i = 1 To 10

  6. For j = 1 To 10

  7. If Cells(i, j).Interior.ColorIndex = 6 Then

  8. sum = sum + Cells(i, j).Value

  9. Count = Count + 1

  10. End If

  11. Next j

  12. Next i


  13. MsgBox Count & "  different Finds"

  14. End Sub
複製代碼
回復 1# stephenlee




歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)