繁体   English   中英

Excel VBA将多列复制到另一张表到一列

[英]excel vba copy multiple columns to another sheet to one column

我需要将多列从一张纸复制到另一列的纸上的帮助。 下面是一个例子。 谢谢!

Adam      Sammy        Roy
111       444          777
222       555          888
333       666          999


Adam
111
222
333
Sammy
444
555
666
Roy
777
888
999

我猜你可以用这些代码做到这一点。

Sub one_column()
Dim numCol As Integer
numCol = Sheet1.Cells(1, Columns.Count).End(xlToLeft).Column
Dim i As Integer
Dim lastRow As Integer
For i = 1 To numCol
    lastRow = Sheet1.Cells(Rows.Count, i).End(xlUp).Row
    Sheet1.Range(Sheet1.Cells(1, i), Sheet1.Cells(lastRow, i)).Copy
    firstBlank = Sheet2.Cells(Rows.Count, 1).End(3).Row
    If firstBlank = 1 Then
    Sheet2.Cells(firstBlank, 1).PasteSpecial
    Else
    Sheet2.Cells(firstBlank + 1, 1).PasteSpecial
    End If

Next

End Sub

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM