View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Greg Wilson Greg Wilson is offline
external usenet poster
 
Posts: 747
Default Manipulating a matrix of data

This puts the transformed data in the 12th column (column L) and doesn't
supplant the existing data. Assumed therefore is that the range of numbers in
any row does not extend that far. Change to suit if they do. The code can of
course be changed to put the transformed data in a different worksheet etc.
Also assumed is that the data starts in cell A1 and ranges down an indefinite
number of rows. Change the cell reference to suit.

After generating the new data, you can check it for accuracy and paste it
over the existing data. The code also handles the situation where there are
no numbers following the letter. It will only return the letter in the
transformed data. If this can never happen then it could be simplified a
little.

Sub TransformData()
Dim r As Range
Dim i As Long, ii As Long
Dim x As Long, xx As Long

Set r = Range(Range("A1"), Range("A1").End(xlDown))
For i = 1 To r.Count
x = IIf(r(i, 2).Value = "", 2, Range(r(i), r(i).End(xlToRight)).Count)
For ii = 2 To x
xx = xx + 1
r(xx, 12).Value = r(i).Value & r(i, ii).Value
Next
Next
End Sub

Greg

"Magenta" wrote:

I am trying to change data from:

A 1 2 3
B 1 2
C 1 2 3 4

(presume that is 3 rows and 5 columns)

to

A 1
A 2
A 3
B 1
B 2
C 1
C 2
C 3
C 4

Can anyone help with formula, or hints on how to get there?