Function CountColor(rColor As Range, rSumRange As Range)
Dim rCell As Range
Dim iCol As Integer
Dim vResult As Integer
iCol = rColor.Interior.ColorIndex
For Each rCell In rSumRange
If rCell.Interior.ColorIndex = iCol Then
vResult = 1
Else
vResult = 0
End If
Next rCell
CountColor = vResult
End Function
我試着鍵入"=CountColor(A1, A2)"
,但我總是得到錯誤"Sub or function not defined"
這是爲什麼?我一直堅持這幾個小時。功能:錯誤Sub或函數未定義
這是在工作簿模塊還是工作表模塊?如果我放置在工作簿模塊中,它適用於我。 – BruceWayne
我認爲這是重複的:http://stackoverflow.com/questions/12351339/cant-use-vba-functions-in-a-spreadsheet-formula-in-excel-2010 – bernie
對不起,有什麼區別他們倆?我通過右鍵單擊項目並創建一個新模塊來插入一個模塊。 – user3002486