我有一个单元格包含多行数据。其中一些行带有删除线。
现在,我想知道该单元格内有多少条线是删除线。
那么,如何通过某些公式或 VBA 来实现这一点?
所有线条要么完全删除,要么不删除。没有部分删除。
我们所说的行是指单元格内以Alt“+”号分隔的行数。Enter
答案1
今天感觉想做一些免费的编码服务......
可以在单元格中=CountStrikeThrough(A2)
或在 VBA 中使用Debug.Print CountStrikeThrough(Sheet1.Range("A2"))
Public Function CountStrikeThrough(Target As Range) As Long
Dim lCount As Long
Dim x As Long
Dim bStrikeInRow As Boolean
For x = 1 To Len(Target)
With Target.Characters(Start:=x, Length:=1)
'If new row character found then reset strike-throughs found in row to false.
If .Text = vbLf Then bStrikeInRow = False
'If character is a strike-through and no strike-throughs found in row yet
'add one to the count and change boolean to strike-throughs found in this row (true).
If .Font.Strikethrough And Not bStrikeInRow Then
bStrikeInRow = True
lCount = lCount + 1
End If
End With
Next x
CountStrikeThrough = lCount
End Function