删除子string,但保留格式

我有一小部分代码将从我select的单元格中删除子string垃圾

Sub RemoveJunk() Dim r As Range For Each r In Selection r.Value = Replace(r.Value, "junk", "") Next r End Sub 

代码有效,但是会破坏单元格中剩余字符的格式。 所以,如果我开始:

在这里输入图像描述

我结束了:

在这里输入图像描述

有没有办法避免干扰字符的格式?

 Sub RemovePreserveFormatting(ByVal Where As Range, Expression As String, Optional ByVal Compare As VbCompareMethod = VbCompareMethod.vbBinaryCompare) Dim c As Range For Each c In Where Dim pos As Long: pos = 0 Do pos = InStr(pos + 1, c.Value, Expression, Compare) If pos = 0 Then Exit Do c.Characters(pos, Len(Expression)).Delete Loop Next End Sub