• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Why do we lose text formatting when we replace part of string, and how to avoid this

ThrottleWorks

Excel Ninja
Hi,
I am replacing part of string from a text value.
When I replace string, I lose text formatting. How do I avoid this.

For example,
Input - > You know what, car driving is awesome (awesome word is in red font and bold type).

When I replace ‘car driving’ with ‘bike riding’ I lose text formatting.
Output - > You know what, bike riding is awesome.

I am using below mentioned code to replace string.

Range("B7:B9").Select
Selection.Replace What:="Jul", Replacement:=MyMonthName, LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

I want to preserve formatting. Can anyone please help in this.
 
Sir, to be honest, I never anticipated that excel will behave in such way.

My perception was, I am writing wrong lines, and correct (replace) code will resolve my issue. :D
 
Back
Top