週四05 2023一月
  1 回复
  3.7K訪問
0
投票
復原
在此先感謝您提供的任何幫助。

在這個網站的幫助下,我創建了以下功能;

函數 ColorFunction(rColor 作為範圍,rRange 作為範圍,可選的 SUM 作為布爾值)
Dim rCell 作為範圍
將 lCol 變暗
昏暗的結果
lCol = rColor.Interior.ColorIndex
如果 SUM = True 那麼
對於 rRange 中的每個 rCell
如果 rCell.Interior.ColorIndex = lCol 那麼
vResult = WorksheetFunction.SUM(rCell, vResult)
如果結束
下一個 rCell
其他
對於 rRange 中的每個 rCell
如果 rCell.Interior.ColorIndex = lCol 那麼
v結果 = 1 + v結果
如果結束
下一個 rCell
如果結束
顏色函數 = vResult
函數結束


在每個目標單元格中,我想要該行中包含指定單元格顏色的所有單元格的總和;
=顏色函數(AR4,H5:AP5,真)

當行中的任何其他單元格 (H5:AP5) 改變顏色時,如何讓目標銷售更新?
你好,

您可以添加代碼: 應用程式.計算 = xlAutomatic 到你的函數:

Function ColorFunction(rColor As Range, rRange As Range, Optional SUM As Boolean)
Dim rCell As Range
Dim lCol As Long
Dim vResult
Application.Calculation = xlAutomatic
lCol = rColor.Interior.ColorIndex
If SUM = True Then
For Each rCell In rRange
If rCell.Interior.ColorIndex = lCol Then
vResult = WorksheetFunction.SUM(rCell, vResult)
End If
Next rCell
Else
For Each rCell In rRange
If rCell.Interior.ColorIndex = lCol Then
vResult = 1 + vResult
End If
Next rCell
End If
ColorFunction = vResult
End Function


請試一試。

阿曼達
  • 頁:
  • 1
有沒有為這個職位尚未作出回复。