说在A1包含中"boy"
,在B1包含中"This is a boy"
,我要B1
基于搜索子字符串A1
,并仅格式化(B1
而不是)整个句子中的子字符串(仅“ boy”)B1
。如果使用“条件格式化”=Search(A1,B1)
或=Isnumber(Search(A1,B1))
“条件格式化”,它将格式化整个句子,这不是我想要的。请告诉我如何解决这个问题。谢谢你。
据我所知,这只能通过VBA来实现。尝试以下(粗略的)子:
Sub bold()
On Error GoTo continue 'Otherwise you will receive an error if the substring is missing
For Each cell In Selection
myString = cell.Offset(0, 1)
mySearch = cell
mySearch_length = Len(mySearch)
mySearch_startPos = WorksheetFunction.Search(mySearch, myString)
cell.Offset(0, 1).Characters(Start:=mySearch_startPos, Length:=mySearch_length).Font.FontStyle = "Bold" 'Change to something else as you wish
continue:
Next cell
End Sub
期望使用与您在上面定义的电子表格相同的设置(子字符串的格式设置为字符串的左侧),并且要求您在运行宏之前选择子字符串。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句