简体   繁体   中英

Replace Text and Change font color

I'm stuck. I was successfully able to replace 3 texts in a column to a specific text. But am unable to change the font of the replaced texts to Red. Would appreciate help. Thanks Following is the current code

Worksheets("HPR").Columns("E").Replace _
What:="IM", Replacement:="Non-IM", _
SearchOrder:=xlByColumns, MatchCase:=True

Worksheets("HPR").Columns("E").Replace _
What:="Comp", Replacement:="Non-IM", _
SearchOrder:=xlByColumns, MatchCase:=True

Worksheets("HPR").Columns("E").Replace _
What:="", Replacement:="Non-IM", _
SearchOrder:=xlByColumns, MatchCase:=True"

Just add the below lines to the beginning of your code.

With Application.ReplaceFormat.Font
    .Subscript = False
    .Color = 255
    .TintAndShade = 0
End With

Now add the below line after all the MatchCase:=True,

ReplaceFormat:=True

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM