Data from rows into columns

Closed
cheryl - Oct 14, 2011 at 04:56 AM
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 - Oct 17, 2011 at 06:09 AM
Hello,

I'm not that great in Excel so I was wondering if there is a way to separate rows and move to different columns in Excel 2007/2010.

I have the huge list data in one column as shown below:
ABC
France
20
FXG
DEF
Germany
GO
15
ABC
INDIA
OXY
20
GHI
LONDON
MUST
27

I wanted the data in this format "ABC France 20 FXG" in four separate columns. Since the data is huge and manually copy pasting using transpose options takes time. Can someone please help me?

Many thanks in advance for looking and solving this!

Regards,
Cheryl

2 responses

rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 766
Oct 15, 2011 at 07:40 AM
how one can identify that what cells belong together?
0
Rizvisa1, T
Thanks for picking this up and apology for being so confusing here...the first 4 data/rows is in Column A in this format as mentioned below
ABC
France
20
FXG
And I want a formula where I can pull up all the four rows in one cell in te following format "ABC France 20 FXG" hope this make sense?
0
Hello, Is there anyone who can help me out with this?
0
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 766
Oct 17, 2011 at 06:09 AM
try this. Correct the sheet name, column etc in the code

Public Sub copyNRowsToColumns()

    Dim sSrcSheet As String
    Dim lSrcRowStart As Long
    Dim iSrcCol As Integer
    
    Dim sTgtSheet As String
    Dim lTgtRowStart As Long
    Dim iTgtCol As Integer
    Dim lRowsToTranspose As Long
    
    Dim lSrcRow As Long
    Dim lTgtRow As Long
    Dim lLastSrcRow As Long
    
    sSrcSheet = "Sheet1"
    lSrcRowStart = 1
    iSrcCol = 1
    
    sTgtSheet = "Sheet1"
    lTgtRowStart = 1
    iTgtCol = 2
    lRowsToTranspose = 4
    
    With Sheets(sSrcSheet)
        lLastSrcRow = .Cells(.Rows.Count, iSrcCol).End(xlUp).Row
        
        For lSrcRow = lSrcRowStart To lLastSrcRow Step lRowsToTranspose
            .Range(.Cells(lSrcRow, iSrcCol), .Cells(lSrcRow + lRowsToTranspose - 1, iSrcCol)).Copy
            Sheets(sTgtSheet).Cells(lTgtRowStart, iTgtCol).PasteSpecial Transpose:=True
            lTgtRowStart = lTgtRowStart + 1
        Next lSrcRow
    End With
End Sub
0