VBBA Excel删除数据 – >保持0

With Range("Q10", Range("Q" & Rows.Count).End(xlUp)) .Replace "*-", "", xlPart, xlByRows, False, False, False .Replace " -", "", xlPart, xlByRows, False, False, False End With With Range("X10", Range("X" & Rows.Count).End(xlUp)) .Replace "*-", "", xlPart, xlByRows, False, False, False .Replace " -", "", xlPart, xlByRows, False, False, False End With Dim threeCell As Range For Each threeCell In Range("Q10", Range("Q" & Rows.Count).End(xlUp)) With threeCell .Value = Trim(.Value) End With Next threeCell 

大家好我使用该代码删除列中的数据。 该列包含像“DE-45”“CZ-DZX”这样的数据,它的工作完美,它删除了“DE-”,它离开细胞只是我想要的问题是,当一个细胞是这样的“DE-03”它给了我一个“3”而不是“03”。

我怎样才能解决这个问题?

谢谢!

这可能有点冒失,但是它的工作原理:

更改。 .Replace "*-", "", xlPart, xlByRows, False, False, False为:

.Replace "*-", "'", xlPart, xlByRows, False, False, False

请注意单个'作为Replacement参数。 这将导致像'05 ,Excel解释为string的值 – 因此不会删除任何零。