我在 Excel 宏中有代码来更改一些文本。例如,改变
文本 111
至
001
代码运行,并更改了文本,但我失去了前导零。我想保留前导零。我尝试了很多东西,比如
jRange.NumberFormat = "###"
.Replace "Text 333", "003", xlWhole, ReplaceFormat:=True
我还尝试在列上设置格式,例如:
jRange.Columns("G").NumberFormat = "###"
这是示例代码
Sub FixIt()
Dim jRange As Range
Set jRange = ActiveSheet.Range("G2:G1000")
With jRange
.Replace "Text 111", "001", xlWhole
.Replace "Text 222", "002", xlWhole
.Replace "Text 333", "003", xlWhole
.Replace "Text 444", "077", xlWhole
End With
End Sub