vba - 如何将 4 列合并为 1 列?

标签 vba excel excel-formula excel-2010

使用office 2010。一切都在同一张纸上。
A B C & D 列中的数据可以更改(每天增加或减少)

我有 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

A B C & D 列的长度可以增加或减少。

最佳答案

这个怎么样?

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

关于vba - 如何将 4 列合并为 1 列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14774806/

相关文章:

vba - InStr(1, cell.Value, "-") 似乎不适用于 Not

vba - 默认情况下,文本框不应滚动到末尾

excel - 在excel中将一列中的数据分成更多列

excel - 如何获取另一个单元格的值

excel - VBA过滤唯一值并将其复制到新工作表

vba - 由于合并单元格而导致复制粘贴范围的错误

excel - 同时将 2 个选定的相邻单元格的内容复制到表格的最后一行

Excel:令人难以置信的收缩和扩展控件

excel - 多个类属性的错误处理

VBA 1004 错误 - 无法设置 Range 类的 FormulaArray 属性