REPLACE HELP

R

Rpettis31

I am trying to remove the leading zeros from a column of values, the code
below works but it also seems to be removing the ending zeros as well.

I tried this which does not workResult1 = Replace(Left(Cells(x, 2), "00", ""))

here is my code.
For x = 2 To 4000
Result1 = Replace(Cells(x, 2), "00", "")
Cells(x, 2) = Result1
Next x
 
P

Patrick Molloy

For x = 2 To 4000
result1 =Cells(x, 2)
do while left(result1,1)="0"
result1 = mid(result1,2)
loop
Cells(x, 2) = Result1
Next
 
R

Rick Rothstein

Your values are text (real numbers would not preserve leading zeroes unless
formatted to do so)? Why? Why not use real numbers and format the cells to
show the number the way you want it to look? Then you wouldn't need any code
as Excel would handle everything for you.
 
Top