Reputation: 25
say cell A1, A2, A3 contains value "00V", cell An contains value "029" I'm doing a comparison for consecutive cells in column A like:
If A1 not equal to A2 then ill copy the cell value of A2 and paste it into a new worksheet in Column A first consecutively.
When I compare 00V and 029 (i.e. both are unequal) ill copy 029 and paste into new sheet
But "029" gets pasted as "29"
How do I fix this in Excel vba?
Upvotes: 0
Views: 2176
Reputation: 44
The easiest way is to add a apostrophe (') in front of the values. When copied, the 0 will be maintained.
Upvotes: 0
Reputation: 58
Convert the target column format to text and then use paste special values. You'll be able to preserve the zeros.
Upvotes: 0
Reputation: 9878
You could use Format(val, "000")
where val
is the value of whatever you're copying.
Or you could use rng.NumberFormat = "000"
where rng
is the destination range of where you're copying the values to.
Upvotes: 2