Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Loop through columns

Hi,

Say I have forenames in column A and family names in column B.

How do I loop through all rows in column B and create
<familyname, <forename in column C?

Thanks for hints on this ;-)

/geir
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Loop through columns

do you need code?

in c1 = a1 & " " & b1

or

one way in code

Sub test()
Dim cell As Range
For Each cell In Range("a1:a50")
cell.Offset(0, 2) = cell.Value & " " & cell.Offset(0, 1).Value
Next

End Sub
--


Gary


"Geir Holmavatn" wrote in message
...
Hi,

Say I have forenames in column A and family names in column B.

How do I loop through all rows in column B and create
<familyname, <forename in column C?

Thanks for hints on this ;-)

/geir



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Loop through columns

Gary Keramidas skrev:

Sub test()
Dim cell As Range
For Each cell In Range("a1:a50")
cell.Offset(0, 2) = cell.Value & " " & cell.Offset(0, 1).Value
Next

End Sub


Great

If I have a column with integers:

12345
2345
345

... and want to split the two last digits into one row and leftpad the
first digits with zeros into another row like this:

12345 0123 45
2345 0023 45
345 0003 45

how can that be done in code..?

/geir
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Loop through columns

maybe something like this

Sub test()
Dim cell As Range
Dim lastrow As Long
lastrow = Range("a65000").End(xlUp).Row
For Each cell In Range("A1:A" & lastrow)
cell.Offset(0, 1).Value = Left(cell.Value, Len(cell.Value) - 2)

Do While Len(cell.Offset(0, 1).Value) < 4
cell.Offset(0, 1).Value = "'0" & cell.Offset(0, 1).Value
Loop
cell.Offset(0, 2).Value = Right(cell.Value, 2)
Next
End Sub

--


Gary


"Geir Holmavatn" wrote in message
...
Gary Keramidas skrev:

Sub test()
Dim cell As Range
For Each cell In Range("a1:a50")
cell.Offset(0, 2) = cell.Value & " " & cell.Offset(0, 1).Value
Next

End Sub


Great

If I have a column with integers:

12345
2345
345

.. and want to split the two last digits into one row and leftpad the first
digits with zeros into another row like this:

12345 0123 45
2345 0023 45
345 0003 45

how can that be done in code..?

/geir



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Loop through Columns Sally[_6_] Excel Programming 3 August 26th 06 10:52 AM
loop over columns kizzie Excel Discussion (Misc queries) 4 August 10th 05 01:31 PM
Loop through columns and then rows Sunryzz Excel Programming 8 December 23rd 04 03:13 PM
loop through columns hotherps[_78_] Excel Programming 6 July 23rd 04 11:40 AM
Loop 20 columns Help! Michael168[_106_] Excel Programming 2 July 2nd 04 12:26 PM


All times are GMT +1. The time now is 11:52 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"