自定义excel公式函数UDF统计条件格式
Custom excel formula function UDF to count Conditional Formatting
有没有人 运行 研究过实际使用条件格式的函数?
有一些用于 kutools 和 albebits 的插件,但它们不是基于公式的(您必须 select 手动进行所有操作)
我找到了这个,但只适用于手动格式化
Function ColorFunction(rColor As Range, rRange As Range, Optional SUM As Boolean)
Dim rCell As Range
Dim lCol As Long
Dim vResult
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
继@Jeeped 和@Comintern 之后...
这对我有用 - 一个简化的例子:
Function WrapCountReds(rRange)
WrapCountReds = rRange.Parent.Evaluate("CountReds(" & _
rRange.Address(False, False) & ")")
End Function
'can't call this directly from a worksheet but can be called via evaluate
Public Function CountReds(rRange As Range)
Dim rCell As Range
Dim vResult
For Each rCell In rRange
If rCell.DisplayFormat.Interior.ColorIndex = 3 Then
vResult = 1 + vResult
End If
Next rCell
CountReds = vResult
End Function
工作表使用示例:
=WrapCountReds("A1:A100")
有没有人 运行 研究过实际使用条件格式的函数?
有一些用于 kutools 和 albebits 的插件,但它们不是基于公式的(您必须 select 手动进行所有操作)
我找到了这个,但只适用于手动格式化
Function ColorFunction(rColor As Range, rRange As Range, Optional SUM As Boolean)
Dim rCell As Range
Dim lCol As Long
Dim vResult
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
继@Jeeped 和@Comintern 之后...
这对我有用 - 一个简化的例子:
Function WrapCountReds(rRange)
WrapCountReds = rRange.Parent.Evaluate("CountReds(" & _
rRange.Address(False, False) & ")")
End Function
'can't call this directly from a worksheet but can be called via evaluate
Public Function CountReds(rRange As Range)
Dim rCell As Range
Dim vResult
For Each rCell In rRange
If rCell.DisplayFormat.Interior.ColorIndex = 3 Then
vResult = 1 + vResult
End If
Next rCell
CountReds = vResult
End Function
工作表使用示例:
=WrapCountReds("A1:A100")