如何将4列合并为1列?

使用Office 2010。
一切都在同一张表。
ABC&D栏中的数据可以变化(每天增加或减less)

我有4列

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 

ABC&D列的长度可以增加减less。

这个怎么样?

 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 

使用下面的。 它接受你需要改变的范围,并返回一个垂直的数组值。 要填充值使用数组公式。

 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 

在这个网站的帮助下get-digital-help.com/

结合列但这只是静态的。

我把它转换成dynamic的意义变化范围。

比如我贴了ABCD IN F

为了使公式更清晰,将在名称pipe理器中input公式

下面是每列的dynamic公式 (名副其实)

 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)),"")))) 

截图

在这里输入图像说明在这里输入图像说明