code dropping zeros in number strand

G

Guest

I'm moving numbers from one column to another and using the below code. When
the number is being moved by the code from column H to column I it drops the
zeros at the beginning of the number. How can I fix this? Also I need to
change the criteria to move any number that is greater than 8 characters. I
tried changing the 13 to 8 or > but that did not work for m. Thanks

Set rng = Range(Cells(2, "H"), Cells(Rows.Count, "H").End(xlUp))
For Each cell In rng
If Len(cell) = 13 Then
cell.Offset(0, 1).Value = cell.Value
cell.ClearContents
End If
Next
 
G

Guest

If you format the detination cells as Text beforerunning the macro, the
leading zeros will be preserved..


also:

if len(cells.value) > 8 then
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top