Sub MyCharacters()
'ExcelHome技术论坛VBA编程学习与实践:看见星光
Dim arr, s$, i&, l&, n&
s = '领导' '需要改变格式的字符串
n = Len(s) '变量s的长度
arr = Range('a1:a' & Cells(Rows.Count, 1).End(xlUp).Row)
For i = 1 To UBound(arr)
l = InStr(1, arr(i, 1), s, vbTextCompare)
'查找变量s在arr(i,1)中首次出现的位置,不区分字母大小写
Do While l '如果l不为0,也就是存在s的话那么……
With Cells(i, 1).Characters(l, n).Font
.Size = 15 '15号字体
.FontStyle = '加粗'
.Color = -16776961 '红色
End With
l = InStr(l + n, arr(i, 1), s, vbTextCompare)
'寻找变量s下一个出现的位置
Loop
Next
MsgBox '处理完毕!'
End Sub
联系客服