【发布时间】:2014-01-15 16:56:10
【问题描述】:
我有一个包含 300 列左右的 Excel 2010 工作表。我需要将所有数据粘贴到一列(未合并)。除了复制一列、滚动到第一列的底部、粘贴并为每一列重复之外,还有其他方法吗?
【问题讨论】:
-
这不是编程问题,所以这里不是问这个问题的地方。
标签: excel
我有一个包含 300 列左右的 Excel 2010 工作表。我需要将所有数据粘贴到一列(未合并)。除了复制一列、滚动到第一列的底部、粘贴并为每一列重复之外,还有其他方法吗?
【问题讨论】:
标签: excel
试试这个(您可能需要将; 更改为,):
【讨论】:
您可以使用以下代码。它将所有值粘贴到列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
【讨论】: