[英]Copy and paste Excel data into one column
I have an Excel 2010 sheet with 300 or so columns. 我有一个包含300个左右列的Excel 2010工作表。 I need all of the data to be pasted into one column (not merged).
我需要将所有数据粘贴到一列(不合并)中。 Is there any way to do this other than copying one column, scrolling to the bottom on the first, pasting, and repeating for every column?
除了复制一列,滚动到第一列的底部,粘贴并为每一列重复之外,还有其他方法吗?
Try this (you may need to change ;
to ,
): 试试这个(您可能需要将
;
更改为,
):
You can use following code. 您可以使用以下代码。 It will paste all values to the column
A
: 它将所有值粘贴到
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
Try this macro 试试这个宏
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.