Convert columns with multiple rows of data to rows with multiple columns in Excel.

前端 未结 4 1640
广开言路
广开言路 2021-01-24 19:26

I have data organised in cloumns with multiple rows which I need to convert to rows with multiple columns for data analysis. For example,

    ID  Date of entry          


        
相关标签:
4条回答
  • 2021-01-24 19:41

    I started from a formula I found on the internet that takes one-column list and changes it's layout to multyple columns: that insteat of 1000+ rows you'll get 60 rows with many columns of that list. you can find it here http://help.lockergnome.com/office/list-multiple-columns-page--ftopict935389.html

    i wanted to take a list that has 4 columns (the 5th column is empty) and 1000+ rows, and make it a 50 rows table that the 4 fields repeats itself.

    for example i have:

    family  |  name   |  amount  |   table |
    fam1    |  shlomi |  2       |   38    |
    fam2    |  hila   |  4       |   23    |    
    ....    
    fam1000 |  avi    |  1       |   15    |
    

    and i want to make it

    family  |  name   |  amount  |   table |     |fam50    |  ben   |  2       |   68    |  ...    
    fam1    |  shlomi |  2       |   38    |      ...    
    fam2    |  hila   |  4       |   23    |      ...    
    ...                                           ...    
    fam49   |  dror   |  1       |   15    |     |fam99    |  dror   |  1      |   15    | ...
    

    On a new worksheet in your existing workbook, insert the following formula into A1:

    =IF(OFFSET(Sheet1!$A$1,QUOTIENT(COLUMN(),5)*50+ROW()-1,MOD(COLUMN()-1,5))="","",OFFSET(Sheet1!$A$1,QUOTIENT(COLUMN(),5)*50+ROW()-1,MOD(COLUMN()-1,5)))

    .. Copy this formula across as many columns as you need, and as many rows as you need ( I used 50 in my example)

    You can change '5' in the furmula to the number of fields you want in each column layout, and you can change '50' to the number of rows you want in each page.

    0 讨论(0)
  • 2021-01-24 19:42

    You'll have to add the headers yourself, but this code should do what you need:

    Sub ConsolidateRows_SpreadAcross()
    
    Dim lastRow As Long, i As Long, j As Long
    Dim colMatch As Variant, colConcat As Variant
    
    application.ScreenUpdating = False 'disable ScreenUpdating to avoid screen flashes
    
    lastRow = range("A" & Rows.Count).End(xlUp).Row 'get last row
    
    For i = lastRow To 2 Step -1
    
        If Cells(i, 2) = Cells(i - 1, 2) Then
            range(Cells(i, 3), Cells(i, Columns.Count).End(xlToLeft)).Copy Cells(i - 1, Columns.Count).End(xlToLeft).Offset(, 1)
            Rows(i).Delete
        Else
            If Cells(i, 1) = Cells(i - 1, 1) Then
                range(Cells(i, 2), Cells(i, Columns.Count).End(xlToLeft)).Copy _
                    Cells(i - 1, Columns.Count).End(xlToLeft).Offset(, 1)
                Rows(i).Delete
            End If
        End If
    
    Next
    
    application.ScreenUpdating = True 'reenable ScreenUpdating
    End Sub
    
    0 讨论(0)
  • 2021-01-24 19:46

    family | name | amount | table | fam1 | shlomi | 2 | 38 | fam2 | hila | 4 | 23 | .... fam1000 | avi | 1 | 15 | fam50 | ben | 2 | 68 |



    dror | 1 | 15 |

    and i want to make it

    family | name | amount | table | |fam50 | ben | 2 | 68 | ...
    fam1 | shlomi | 2 | 38 | ...
    fam2 | hila | 4 | 23 | ...
    ... ...
    fam49 | avi | 1 | 15 | |fam99 | dror | 1 | 15 | ...

    0 讨论(0)
  • 2021-01-24 19:54

    If you copy the whole table, and then right-click wherever you want to paste the new data, you should be given the menu "Paste Special." From that menu, choose transpose. That should transpose the columns into rows.

    0 讨论(0)
提交回复
热议问题