【问题标题】:How to transpose multiple columns into a single column?如何将多列转置为一列?
【发布时间】:2013-06-03 02:11:29
【问题描述】:

在数量上,如何转置这种格式:

一个 a1 b b1 c c1 d d1 e e1

如下图的单列?

一个
a1
b
b1
C
c1
d
d1

【问题讨论】:

    标签: excel excel-formula worksheet-function excel-indirect vba


    【解决方案1】:

    有很多方法可以实现您想要的。最简单的描述之一是,假设您的数据在 ColumnA:B 中,使用 C1 中的公式并复制下来;

    =IF(ISODD(MOD(ROW(),2)),INDIRECT(CHAR(COLUMN()+61)&(ROW()+1)/2), INDIRECT(CHAR(COLUMN()+62)&(ROW()/2)))

    但我喜欢的一种技术几乎不需要公式(Excel 在按钮后面提供的除外)。小计 A:B(A:B 需要标签,即使是空白)对于 ColA、计数、将小计添加到 ColA 和数据下方的摘要中的每个更改。 {这是为了添加行,如果 ColA 具有连续的重复值,则会下降 - 计数应始终为 1)。

    过滤 A:C 并选择 B = 1。在B3 中输入=C2 并根据需要向下复制。取消过滤,复制 ColB 并将特殊值粘贴到顶部。删除小计并删除 {new} ColA 以保持整洁。 {现在也可以删除 ColB。}

    PS 如果您的数据在您的帖子中似乎显示在交替行中,这会更容易 - 在我编辑之前!

    【讨论】:

      【解决方案2】:

      您也可以使用 VBA 执行此操作,而无需让 Excel 选择或激活任何内容。它现在只被编码为在活动工作表上工作,但它很容易让它在任何未被积极选择的工作表上工作。

      Sub combineColumns()
      
              Dim sFirstCol As String
              Dim sSecondCol As String
      
              sFirstCol = "A"
              sSecondCol = "B"
      
              Dim values() As String
              Dim i As Integer
              Dim t As Integer
              Dim iFirstRow As Integer
              Dim iSecondRow As Integer
              iFirstRow = Range(sFirstCol & 1).End(xlDown).Row
              iSecondRow = Range(sSecondCol & 1).End(xlDown).Row
      
              ReDim values(iSecondRow - 1)
      
              For i = 0 To iFirstRow - 1
                  values(i) = Range(sSecondCol & i + 1).Value
              Next i
      
              t = 0
              For i = 0 To iFirstRow * 2 - 1 Step 2
                  Range(sFirstCol & i + 2).Insert
                  Range(sFirstCol & i + 2).Value = values(t)
                  t = t + 1
              Next i
      
              Range(sSecondCol & 1 & ":" & sSecondCol & iSecondRow * 2).ClearContents
      
       End Sub
      

      【讨论】:

        猜你喜欢
        • 2018-03-09
        • 1970-01-01
        • 1970-01-01
        • 2017-08-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-11-17
        • 1970-01-01
        相关资源
        最近更新 更多