将Excel数据复制并粘贴到一列中
我有一张Excel 2010表格,大约有300列。我需要将所有数据粘贴到一列中(不合并)。除了复制一列、滚动到第一列的底部、粘贴并对每一列重复之外,还有其他方法吗?尝试一下(您可能需要将将Excel数据复制并粘贴到一列中,excel,Excel,我有一张Excel 2010表格,大约有300列。我需要将所有数据粘贴到一列中(不合并)。除了复制一列、滚动到第一列的底部、粘贴并对每一列重复之外,还有其他方法吗?尝试一下(您可能需要将;更改为,): 试试这个(您可能需要将;更改为,): 您可以使用以下代码。它将所有值粘贴到列A: Sub test() Dim lastCol As Long, lastRowA As Long, lastRow As Long, i As Long 'find last non empty c
;
更改为,
):
试试这个(您可能需要将;
更改为,
):
您可以使用以下代码。它将所有值粘贴到列
A
:
Sub test()
Dim lastCol As Long, lastRowA As Long, lastRow As Long, i As Long
'find last non empty column number'
lastCol = Cells(1, Columns.Count).End(xlToLeft).Column
'loop through all columns, starting from column B'
For i = 2 To lastCol
'find last non empty row number in column A'
lastRowA = Cells(Rows.Count, "A").End(xlUp).Row
'find last non empty row number in another column'
lastRow = Cells(Rows.Count, i).End(xlUp).Row
'copy data from another column'
Range(Cells(1, i), Cells(lastRow, i)).Copy
'paste data to column A'
Range("A" & lastRowA + 1).PasteSpecial xlPasteValues
'Clear content from another column. if you don't want to clear content from column, remove next line'
Range(Cells(1, i), Cells(lastRow, i)).ClearContents
Next i
Application.CutCopyMode = False
End Sub
您可以使用以下代码。它将所有值粘贴到列
A
:
Sub test()
Dim lastCol As Long, lastRowA As Long, lastRow As Long, i As Long
'find last non empty column number'
lastCol = Cells(1, Columns.Count).End(xlToLeft).Column
'loop through all columns, starting from column B'
For i = 2 To lastCol
'find last non empty row number in column A'
lastRowA = Cells(Rows.Count, "A").End(xlUp).Row
'find last non empty row number in another column'
lastRow = Cells(Rows.Count, i).End(xlUp).Row
'copy data from another column'
Range(Cells(1, i), Cells(lastRow, i)).Copy
'paste data to column A'
Range("A" & lastRowA + 1).PasteSpecial xlPasteValues
'Clear content from another column. if you don't want to clear content from column, remove next line'
Range(Cells(1, i), Cells(lastRow, i)).ClearContents
Next i
Application.CutCopyMode = False
End Sub
试试这个宏
Sub combine_columns()
Dim userResponce As Range
Columns(1).Insert ' insert new column at begining of worksheet
lrowEnd = 1 'set for first paste to be cell A1
'get user selection of data to combine
Set userResponce = Application.InputBox("select a range with the mouse", Default:=Selection.Address, Type:=8)
'this IfElse can be removed once macro is tested.
If userResponce Is Nothing Then
MsgBox "Cancel clicked"
Else
MsgBox "You selected " & userResponce.Address
End If
Set a = userResponce
'this loops through the columns selected and pastes to column A in a stacked foormat
For Each b In a.Columns
Rng = "A" & lrowEnd
Range(b.Address).Copy
Range(Rng).PasteSpecial
lrowEnd = Cells(Rows.Count, "A").End(xlUp).Row + 1 'find next blank row
Next
End Sub
试试这个宏
Sub combine_columns()
Dim userResponce As Range
Columns(1).Insert ' insert new column at begining of worksheet
lrowEnd = 1 'set for first paste to be cell A1
'get user selection of data to combine
Set userResponce = Application.InputBox("select a range with the mouse", Default:=Selection.Address, Type:=8)
'this IfElse can be removed once macro is tested.
If userResponce Is Nothing Then
MsgBox "Cancel clicked"
Else
MsgBox "You selected " & userResponce.Address
End If
Set a = userResponce
'this loops through the columns selected and pastes to column A in a stacked foormat
For Each b In a.Columns
Rng = "A" & lrowEnd
Range(b.Address).Copy
Range(Rng).PasteSpecial
lrowEnd = Cells(Rows.Count, "A").End(xlUp).Row + 1 'find next blank row
Next
End Sub
这不是编程问题,所以这里不是提问的地方。这不是编程问题,所以这里不是提问的地方。