开发者

Multiple columna and rows to Single Rows.. in Excel

I have a sheet with 20 rows and 5 columns. I have to make this appear on one row.

Below is a sample:

147818  5674    96.30%  4722438 367902
153838  5208    96.73%  4201230 275551
56169   2168    96.28%  3631067 154791
9757    783 92.57%  554416  60998
15063   693 95.60%  792926  52139
7066    399 94.66%  398510  25428
205000  5801    97.25%  7911647 362787
54350   2333    95.88%  2539515 180496
20078   1499    93.05%  1126588 198589
18017   1529    92.18%  822311  81328
37197   1588    95.91%  2119084 194785
62698   3029    95.39%  2335887 166912
79456   2706    96.71%  3085981 327617
15849   958 94.30%  905078  71673
43315   2276    95.01%  2598093 227995
41327   2797    93.66%  1655517 152436
50671   2697    94.95%  2058479 254505
41164   1695    96.05%  1648804 91573

I have to make this display in a single row:

147818  5674    96.30%  4722438 367902 153838   5208    96.73%  4201230 275551 56169    2168    96.28%  3631067 开发者_StackOverflow社区154791   ....

Can you suggest to me any formula or a VBA functions?


How about going through all the rows a copying them one by one ..

Sub CombineRows()

Dim i As Integer, N As Integer, M As Integer
Dim row_values() As Variant
Dim r_read As Range, r_write As Range
'Set to top-left of input values
Set r_read = Range("A1")
'Set to top-left of output row
Set r_write = Range("A21")
'Count the rows to read
N = Range(r_read, r_read.End(xlDown)).Rows.Count
'Count the columns to read
M = Range(r_read, r_read.End(xlToRight)).Columns.Count

For i = 1 To N
    'Read an entire row into an array
    row_values = r_read.Offset(i - 1, 0).Resize(1, M).Value
    'Write the row from the array
    r_write.Offset(0, (i - 1) * M).Resize(1, M).Value = row_values
Next i

End Sub

Stick this in the sheet somewhere, press Alt-F8 or select Tools/Macro/Macros and run it. Make sure it point to the correct places in your data sheet.


This will work. You need to highlight your data on the spreadsheet first:

Sub ConvertToRow()
    Dim cl As Range, cnt As Long, targetRow As Range
    Set targetRow = Range("A1") 'change this for where you want the ouput
    cnt = 0

    For Each cl In Selection
        targetRow.Offset(0, cnt) = cl
        cnt = cnt + 1
    Next cl
End Sub
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜