views:

250

answers:

1

Hi All

I have a big problem in the moment. I have to sort out an Excel sheet with names in it. There is always a first name and a last name following each other in the same order. Each name fills a cell. These Cells are alligned in one row. Example

Bill|Cospy|James|Bond|George|Clony|Michael|Jacksson

Now I want that each first name and second name are summarized into one cell and then the next first name and second name are taken for the same procedure. The result should be this:

Bill Cospy
James Bond
George Clony
Michael Jackson

Can someone write me script which does this?

(I take Visual basic or Applescript, it doesn't matter)

+2  A: 

In Excel VBA

Dim curRow As Integer
Dim curCol As Integer

curRow = 1
curCol = 1

For Each c In Range("1:1") 'target row number'

    If c.Value = "" Then 'we have hit a blank cell in target row'
        Exit Sub
    End If

    Cells(curRow, curCol).Value = c.Value

    curCol = curCol + 1
    If curCol = 3 Then
       curRow = curRow + 1
       curCol = 1
    End If

Next c
Mark
Thank you very much for your helpful cooperation in this delicate situation! You're a real live saver ;)
elhombre