【发布时间】:2020-11-06 18:42:32
【问题描述】:
我有一些由前同事编写的代码,用于计算具有特定字符串的合并单元格。例如,如果有一个大小为 3 且名称为“Youtube”的合并单元格,它将返回 3。
这是有问题的函数:
Function MergedCellsCount(rRange As Range, crit As Variant) As Double
Application.Volatile
MergedCellsCount = 0 'in case there are no matches
For Each c In rRange
If LCase(c.Value) = LCase(crit) Then
MergedCellsCount = MergedCellsCount + c.MergeArea.Cells.Count
prev_rng = c.MergeArea.Address
End If
Next
' MergedCellsCount = MergedCellsCount / 5
End Function
但是现在,我想计算在该字符串中具有子字符串的单元格。 例如,如果有一个大小为 3 的合并单元格与“Youtube | Spotify”,我想知道如何更改该函数以搜索子字符串“Youtube”。
关于如何实现这一点的任何建议?
提前致谢!
【问题讨论】: