2011-05-09 25 views
0

我有一个工作表20行5列。我必须使它出现在一行上。多列columna和行到单行..在Excel中

下面是一个示例:

147818 5674 96.30% 4722438 367902 
153838 5208 96.73% 42
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 

我不得不在一个单行此显示:

147818 5674 96.30% 4722438 367902 153838 5208 96.73% 42.28% 3631067 154791 .... 

您能否提供给我任何公式或VBA函数?

回答

1

如何经历的所有行的复制逐一..

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 

棒这片地方,按Alt-F8或选择工具/宏/ 并运行它。确保它指向数据表中的正确位置。

+0

感谢。它的正常工作 – 2011-05-10 04:10:02

+0

也许你应该做的小复选标记啄并接受这个答案。 – ja72 2011-05-10 05:28:11

0

这将工作。首先,您需要突出的电子表格上的数据:

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

Gr8,感谢您的快速支持... – 2011-05-10 04:15:28