Thread: Simple loop?
View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
KL KL is offline
external usenet poster
 
Posts: 201
Default Simple loop?

Hi bushtor,

Say column B in an Excel sheet contains ForeNames and column C contains
FamilyNames, how would I merge these two together in an inserted Column
D as <forename<space<familyname?


Try this:

Sub test()
With ActiveSheet
Set rng = .Range(.Cells(2, "B"), _
.Cells(.Rows.Count, "B").End(xlUp))
End With
For Each c In rng
c.Offset(, 2) = Trim(c & " " & c.Offset(, 1))
Next c
End Sub


Also another column contains numeric values with 3 or 4 digits. I need
to pad these numbers with a leading zeros making 234 to 0234 and also
convert this field to a string field to make sure that excel doesn't
strip this zero off again. How would I do this..?


Sub test2()
With ActiveSheet
Set rng = .Range(.Cells(2, "B"), _
.Cells(.Rows.Count, "B").End(xlUp))
End With
For Each c In rng
c.NumberFormat = "@"
c = Format(c, "0000")
Next c
End Sub

Regards,
KL