Divide a long vertical string into shorter horizontal strings with VBA

bilbon

Board Regular
Joined
Dec 19, 2011
Messages
83
Hi
Can someone help me with VBA code to divide a long vertical string into horizontal strings that are 13 characters long and separated by comma. Each string shall begin with an E. The vertical string is in column A and may be different long, the result shall be written in column C.


/Bilbon





1E,1,2,2,X,1,2,1,2,1,2,2,X,X
2E,2,1,1,2,1,X,1,2,X,X,X,1,2
2E,2,X,X,1,2,1,1,1,1,X,X,2,1
X
1
2
1
2
1
2
2
X
X
2
1
1
2
1
X
1
2
X
X
X
1
2
2
X
X
1
2
1
1
1
1
X
X
2
1

<colgroup><col><col><col></colgroup><tbody>
</tbody>
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Give this macro a try...
Code:
[table="width: 500"]
[tr]
	[td]Sub LongListToE13s()
  Dim R As Long, Data As Variant, Result As Variant
  Data = Range("A1", Cells(Rows.Count, "A").End(xlUp))
  ReDim Result(1 To 1 + Int(UBound(Data) / 13), 1 To 1)
  For R = 1 To UBound(Data) Step 13
    Result((R + 12) / 13, 1) = "E," & Join(Application.Transpose(Application.Index(Data, Evaluate("ROW(" & R & ":" & R + 12 & ")"), 1)), ",")
  Next
  Range("C1").Resize(UBound(Result)) = Result
End Sub[/td]
[/tr]
[/table]
 
Upvote 0

Forum statistics

Threads
1,215,491
Messages
6,125,104
Members
449,205
Latest member
ralemanygarcia

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top