VBA Change Cell part text with your specific word


Sub ChangeSearchCharFontColor(ByVal SearchChar As String)

'ColorIndex=41(青色)
Dim strColorIndex As Integer: strColorIndex = 41

'色変換する文字列の開始Position
Dim startPos As Integer: startPos = 1

Dim matchPos As Integer: matchPos = 0

'置き換えをしたい文字列
'SampleText : trgText = This is VBA.
Dim trgText As String: trgText = ActiveCell.Value

'---- 検索する文字列の長さ
Dim SearchCharLen As Integer: SearchCharLen = Len(SearchChar)
'-------------------------------
'SampleText : SearchChar = VBA
While 0 <> InStr(startPos, trgText, SearchChar, vbTextCompare)

'ここで文字列を比較してビットする文字列の開始Position取得
matchPos = InStr(startPos, trgText, SearchChar, vbTextCompare)

'文字列の部分テキスト青色に変換する
ActiveCell.Characters(Start:=matchPos, Length:=SearchCharLen).Font.ColorIndex = strColorIndex
'
'比較する文字列の開始Position変更(変更しないと同じ検索テキスト複数ある場合はじめのテキストのみ色変換される)
startPos = matchPos + SearchCharLen

Wend

End Sub

----------------------------------------------------------------
Result : This is VBA.