2013-02-08 84 views
1

使用office 2010.
一切都在同一張表中。
數據在列A B C & d可以改變(增加或減少每日)如何將4列合併爲1列?


我有4列列A B C & d可以增加減少的

      OUTPUT --> IN column F should be 
---A-----B-----C------D---------------------------------------F 
    1  5  8  AP          1 
    2  6  9  BP          2 
    3  7  1  CD          3 
    4   5  QW          4 
                   5 
                   6 
                   7 
                   8 
                   9 
                   1 
                   5 
                   AP 
                   BP 
                   CD 
                   QW 

長度。

+0

護理,告訴我們你試圖讓這個做了什麼? – 2013-02-08 14:34:10

+0

嗨朋友)假設「數據在列A B C&D可以改變」 - 我會看VBA。你有嘗試過什麼嗎? – 2013-02-08 14:34:10

+0

我已經知道它可以在1列中組合,但不會跟上範圍。 – Mowgli 2013-02-08 14:37:13

回答

1

這個怎麼樣?

Sub move() 
    Dim ws As Worksheet 
    Dim outputColumn As Long 
    Dim currentColumn As Long 
    Dim currentOutputRow As Long 

    Set ws = ActiveSheet 
    outputColumn = 6 ' column f 

    For currentColumn = 1 To 4 
     currentOutputRow = ws.Cells(ws.Rows.Count, outputColumn).End(xlUp).Row 
     If (currentOutputRow > 1) Then 
      currentOutputRow = currentOutputRow + 1 
     End If 

     ws.Range(ws.Cells(1, currentColumn), ws.Cells(ws.Rows.Count, currentColumn).End(xlUp)).Copy _ 
      ws.Cells(currentOutputRow, outputColumn) 
    Next 
End Sub 
+0

感謝它的工作,但仍然很少的事情,它也包括行1,它不應該,我知道這將總是弄亂了東西,如果它不是A B C D?如果是I,O,P Q? – Mowgli 2013-02-08 14:50:39

+0

@Mowgli你可以通過修改它從'ws.Cells(1,currentColumn)'複製到'ws.Cells(2,currentColumn)'的最後一行來修改它以使用第2行和第2行。對於列問題,您將不得不創建一個包含所需列的數組,然後循環而不是'1到4' – 2013-02-08 18:27:07

1

使用以下。它接受你需要改變的範圍,並返回一個垂直的數組值。要填充值,請使用數組公式。

Function ToVector(rng As Range) 

    Dim cells() 
    ReDim cells(rng.cells.Count) 

    Dim i As Double 

    For Each cell In rng 

     cells(i) = cell 
     i = i + 1 

    Next cell 

    ToVector = Application.WorksheetFunction.Transpose(cells) 

End Function 
1

有了這個網站get-digital-help.com/

Combine Columns的幫助但這僅僅是靜態的。

我將它轉換爲動態含義變化範圍。

例如我張貼ABCD IN F

爲了使配方更加清楚將在名稱管理器中輸入公式

下面是每一列動態公式(以名馬槽雲)

ALIST = =OFFSET($A$1,0,0,COUNTA($A:$A),1) 
BLIST = =OFFSET($B$1,0,0,COUNTA($B:$B),1) 
CLIST = =OFFSET($C$1,0,0,COUNTA($C:$C),1) 
DLIST = =OFFSET($D$1,0,0,COUNTA($D:$D),1) 

公式欄F並拖下去

=IFERROR(INDEX(ALIST, ROWS(F$1:$F1)), 
    IFERROR(INDEX(BLIST, ROWS(F$1:$F1)-ROWS(ALIST)), 
    IFERROR(INDEX(CLIST, ROWS(F$1:$F1)-ROWS(ALIST)-ROWS(BLIST)), 
    IFERROR(INDEX(DLIST, ROWS(F$1:$F1)-ROWS(ALIST)-ROWS(BLIST)-ROWS(CLIST)),"")))) 

截圖

enter image description here enter image description here