vba - Excel/VBA 计算字符串中有多少个粗体单词

标签 vba excel count

从昨天开始,我拼命地计算单元格中有多少个单词是粗体。

类似“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/

相关文章:

c# - 为什么此代码会导致 Excel 无法正常关闭?

mysql - 如何从Mysql取回没有统计数据的日子的数据

python - 在 Python 中计算字典中不同键的数量

mysql order by count 性能

c# - 自动将思维导图转换为另一个应用程序(在 MS Project 中)

arrays - Excel vba : Property let procedure not defined and property get procedure did not return an object

c# - 如何创建 CSV 以便数字在电子表格中显示为字符串?

excel - sumif 其中行范围由另一个单元格确定

vba - 在 Excel 中按单元格值获取列号

vba - 重命名文件夹 vba 中的文件