2014-01-15 72 views
0

我有一個包含300列左右的Excel 2010工作表。我需要將所有數據粘貼到一列(未合併)。除了複製一列以外,還有其他辦法可以做到這一點,第一次滾動到底部,粘貼並重復每一列。將Excel數據複製並粘貼到一列中

+0

這不是編程問題,所以這不是問這個地方。 –

+0

@ZilbermanRafael或者它是? (到目前爲止,A是兩個腳本和一個相當複雜的公式)。 – pnuts

回答

3

試試這個(您可能需要更改;,):

enter image description here

1

您可以使用下面的代碼。它將所有的值粘貼到列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 
0

試試這個宏

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 
相關問題