如何仅在Excel中有条件地格式化子string

在A1中包含"boy" ,在B1中包含"This is a boy" ,我想在B1search基于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 

这需要与上面定义的电子表格的设置相同(将子string格式化string的左侧),并要求您在运行macros之前select子string。