Move every 3 rows into a column in excel
Posted
by
Eliane El Asmr
on Super User
See other posts from Super User
or by Eliane El Asmr
Published on 2014-06-04T08:30:35Z
Indexed on
2014/06/04
9:28 UTC
Read the original article
Hit count: 267
Please i need your help. I need to move every 3 rows into a new colomn. --Let's suppose i have this:
Ambassade de France S.E. M. Patrice PAOLI 01-420000-420150
Ambassade de France Mme. Jamilé Anan 01-420000-420150
Ambassade de France Mme . Marie Maamari 01-420000-420150
--I need them to be Like this: Ambassade de France S.E. M. Patrice PAOLI 01-420000-420150 Ambassade de France Mme. Jamilé Anan 01-420000-420150 Ambassade de France Mme . Marie Maamari 01-420000-420150
I have this code. Can you help me Please. It's giving me error. Out of range. What should i change? It's urgent:(the code is for every 7, i need for every 3)
Sub Every7()
Dim i As Integer, j As Integer, cl As Range
Dim myarray(100, 6) As Integer 'I don't know what your data is. Mine is integer data
'Change 100 to however many rows you have in your original data, divided by seven, round up
'remember arrays start at zero, so 6 really is 7
If MsgBox("Is your entire data selected?", vbYesNo, "Data selected?") <> vbYes Then
MsgBox ("First select all your data")
End If
'Read data into array
For Each cl In Selection.Cells
Debug.Print cl.Value
myarray(i, j) = cl.Value
If j = 6 Then
i = i + 1
j = 0
Else
j = j + 1
End If
Next
'Now paste the array for your data into a new worksheet
Worksheets.Add
Range(Cells(1, 1), Cells(101, 7)) = myarray
End Sub
Thank you.
© Super User or respective owner