Excel 更改为单元格中的粗体重复文本
我正在尝试编写一些代码,在excel单元格中查找是否包含我要查找的单词,并将其加粗。到目前为止,我已经编写了以下代码Excel 更改为单元格中的粗体重复文本,excel,vba,Excel,Vba,我正在尝试编写一些代码,在excel单元格中查找是否包含我要查找的单词,并将其加粗。到目前为止,我已经编写了以下代码 With Worksheets("Label Print").Cells(i, J) .Characters(Start:=InStr(.Value, “Name”), Length:=Len(“Name”)).Font.Bold = True End With 问题是,如果“Name”在一个单元格中出现两次(或更多),它将只突出显示其第一次出现 提前感谢您这里有一个函数,用于
With Worksheets("Label Print").Cells(i, J)
.Characters(Start:=InStr(.Value, “Name”), Length:=Len(“Name”)).Font.Bold = True
End With
问题是,如果“Name”在一个单元格中出现两次(或更多),它将只突出显示其第一次出现
提前感谢您这里有一个函数,用于检查单元格和搜索单词,并将该单词的所有大小写都加粗:
Public Sub BoldWord(rngCell As Range, sWord As String)
Dim iPlace As Integer
iPlace = InStr(1, rngCell.Value, sWord, vbTextCompare)
Do While iPlace > 0
rngCell.Characters(Start:=iPlace, Length:=Len(sWord)).Font.Bold = True
iPlace = InStr(iPlace + 1, rngCell.Value, sWord, vbTextCompare)
Loop
End Sub
注1:rngCell必须是单个单元格
注2:搜索不区分大小写。。。如有必要,请更改vbTextCompare。效果很好!!明亮的