Move every 3 rows into a column in Excel

2

Please I need your help. I need to move every 3 rows into a new column. 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? (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

Eliane El Asmr

Posted 2014-06-04T08:30:35.617

Reputation: 21

Great question, good use of showing the expected outcome. – Dave – 2014-06-04T11:47:00.247

Answers

1

Try this:

  1. Replace number "6" with "2" and
  2. Replace number "7" with "3" in your code.

Note: Dim myarray(100, 2) - The 100 in this line is the total number of rows you have. If you have (let's assume) 50 rows then change it to 50.

Ĭsααc tիε βöss

Posted 2014-06-04T08:30:35.617

Reputation: 1 772

Type mismatch 13. the error is on this line: myarray(i, j) = cl.Value. I tried to change the array to string. If j = 6 Then i = i + 1 j = 0 This i went to 46. – Eliane El Asmr – 2014-06-04T08:56:36.840

It worked. I had to change the type from integer to String. and It still gave me the errors that gave me before. But i had the excel in the wanted form :) – Eliane El Asmr – 2014-06-04T09:49:57.163

@ElianeElAsmr, if this helped, then please do mark it as an answer so others can see. – Dave – 2014-06-04T11:46:36.423

How do i mark it as answered? :p It's my first time here – Eliane El Asmr – 2014-06-04T12:10:57.223

see left side of my answer two triangles are there, move your mouse below the second triangle symbol..you'll get GREEN color tick mark..click once..that's it. – Ĭsααc tիε βöss – 2014-06-04T15:17:17.017