简体   繁体   English

将Excel数据复制并粘贴到一列中

[英]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.

相关问题 根据列名将数据一个 excel 复制并粘贴到另一个 excel 包括空白单元格 - copy and paste the data one excel to another excel based on column name include blank cells 将粘贴的Excel数据复制到 - Copy paste Excel data in Excel:如何将数据粘贴到一列中? - Excel : how to paste data in one column? 在Excel中将数据从一列移动到另一列,而无需复制/剪切和粘贴 - Movng data in Excel from one column to another without copy/cut & paste 从一列复制数据,粘贴到第一个空列 - Copy data from one column, paste in first empty column excel 工作表数据复制和粘贴,而列 header 计数不同 - excel sheets data copy and paste while column header count differs EXCEL VBA限制复制并粘贴到当前列以进行数据验证列 - EXCEL VBA limit copy and paste to current column for data validation columns 仅当 Excel VBA 中存在数据(例如名称)时才复制和粘贴列 - Copy and Paste a Column only if data is present above it (Such as a name) in Excel VBA 如何在两张Excel工作簿之间将数据从一列复制并粘贴到另一张……而不会覆盖目标列的内容。 - how to copy & paste the data from one column to another between two sheets of excel workbook…without overwriting the destination column content..? Excel宏复制单元格范围并将数据粘贴到另一个工作表 - Excel Macro Copy cell range & paste data one sheet to another
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM