View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Gary''s Student Gary''s Student is offline
external usenet poster
 
Posts: 11,058
Default macro to add leading zeroes to number and loop

Sub fixum()
n = Cells(Rows.Count, "E").End(xlUp).Row
For i = 1 To n
v = Cells(i, "E")
l = Len(v)
If l = 6 Then
Else
v = Application.WorksheetFunction.Rept("0", 6 - l) & v
Cells(i, "E").NumberFormat = "@"
Cells(i, "E").Value = v
End If
Next
End Sub

--
Gary''s Student - gsnu200772


"maijiuli" wrote:

Hello,

I have a data set of employee numbers. the numbers range from 1 - 6
characters and can be all numbers or have letters. I need to compare this to
another worksheet but need to convert the EE numbers to text and all must be
6 characters long. So I need to do the leading zeroes for all EE numbers.
The EE numbers are found on column E and the range can differ week to week so
I would also need to do a loop until there is nothing left in row E (not sure
how to do that one?).

I wish to have a macro so others can use too. Thanks for looking,

--
Thank You!