从昨天开始,我拼命地计算单元格中有多少个单词是粗体。
类似“foo foo foo”应该给出1,“foo foo foo”应该给出2。
这是我最好的尝试,但它返回错误或#VALUE:
Function CountBold(WorkRng As Range)
Dim Rng As Range
Dim xCount As Long
Dim i As Integer
Dim j As Long
Dim arText() As Variant
Rng = WorkRng.Cells(1, 1).Value
arText = Split(Rng.Value, " ")
For i = LBound(arText) To UBound(arText)
j = InStr(0, Rng.Value, arText(i), 1)
If j <> 0 Then If Rng.Characters(j, Len(arText(i))).Font.Bold Then xCount = xCount + 1
Next i
CountBold = xCount
End Function
非常感谢任何帮助! 先感谢您! 弗朗西斯科
最佳答案
试试这个:
Function CountBold(WorkRng As Range)
Dim i, xcount As Integer
For i = 1 To Len(WorkRng)
If WorkRng.Characters(i, 1).Font.Bold = True Then
xcount = xcount + 1
End If
Next i
CountBold = xcount
End Function
关于vba - Excel/VBA 计算字符串中有多少个粗体单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22400422/