View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.misc
Rick Rothstein \(MVP - VB\) Rick Rothstein \(MVP - VB\) is offline
external usenet poster
 
Posts: 2,202
Default Split & Rearrange number

Give this macro a try...

Sub SplitCellText()
Dim X As Long
Dim Combo As String
Dim Values() As String
Combo = Replace(Replace(Range("A1").Value, vbCr, " "), vbLf, " ")
Do While InStr(Combo, " ")
Combo = Replace(Combo, " ", " ")
Loop
Values = Split(Trim(Combo))
For X = 0 To UBound(Values)
Range("A1").Offset(0, X).Value = Values(X)
Next
End Sub

Rick


"Jeff" wrote in message
...
Hi Max, thanks for your reply.

The data is in cell A1 only. Not A1:A3. If using your method, original
data

1234 23244
4434 121 1442
534 121223 12

will change to
A B
1 1234 23244
where next row data 4434 121 1442 & 534 121223 122 will be gone. The
output
should be

A B C D E F G H
1 1234 23244 4434 121 1442 534 121223 12

Rgds..Jeff


"Max" wrote:

One play which would bring you close ..

Assuming the data as posted is in A1:A3
Select A1:A3, click Data Text to Columns, delimited.
In step 2, check "Space" Finish. This splits the data into cols A to C.

Then to extract the contents in A2:C3 into row 1,
you could place this in D1:
=OFFSET($A$2,INT((COLUMNS($A:A)-1)/3),MOD(COLUMNS($A:A)-1,3))
Copy D1 across to I1. Kill the formulas with an "in-place" copy n paste
special as values. Clean up by clearing A2:C3.

The "3" in the OFFSET formula refers to the number of source cols (in the
above, its 3 cols - cols A to C). Adjust to suit.

A better way might be to extract the split data
in cols A to C down a col, instead of across a row.

Eg you could place this instead in say E2:
=OFFSET($A$1,INT((ROWS($1:1)-1)/3),MOD(ROWS($1:1)-1,3))
then copy E2 down as far as required to exhaust the source data,
kill the formulas & clean up by using autofilter on col E,
filter for zero, and delete all zero lines, remove autofilter.
--
Max
Singapore
http://savefile.com/projects/236895
xdemechanik
---
"Jeff" wrote:
Hi,

My excel file Cell A1 has the following format (Multiple numbers in
diff rows)
1234 23244
4434 121 1442
534 121223 12

How do I split & re-arrange the data to 1234 (Cell A1) 23244 (Cell B1)
4434
(Cell C1) etc.. ?

Thanks for your help.