【问题标题】:Need to convert multiple columns to rows需要将多列转换为行
【发布时间】:2016-08-22 04:37:08
【问题描述】:

我有一个看起来像这样的数据集

Host, software 1, software 2. software 3......

我需要它看起来像这样

host,software 1
host,software 2
host,software 3

非常感谢您对此的任何提示或建议。

谢谢

【问题讨论】:

  • (1) 使用Text-To-Column 将行转换为多列,(2) 选择结果并将其复制(3) 使用Transpose 选项将其粘贴到列B 和( 4) 将单词host 一直复制到A 列中。完成。
  • 或者您可以复制数据 > 右键单击​​要粘贴的位置 > 选择性粘贴 > 转置。然后您可以复制Host并将其粘贴到左侧的列中以便重复。

标签: excel rows


【解决方案1】:

您熟悉 VBA 吗?如果是这样,试试这个。只需将其粘贴到模块中并运行它。我确信这不是最有效的方法,但它可以完成工作。

我还假设您只有 3 个软件专栏。如果有更多,则需要将“for j = 1 to 3”部分更改为“for j = 1 to X”,其中 X 是您拥有的列数。

Sub transfer()

'Please make sure to change the name of the sheets to reflect the _
 correct worksheet names.
Dim wkInput As Worksheet: Set wkInput = Worksheets("sheet1")
Dim wkDest As Worksheet: Set wkDest = Worksheets("sheet2")

'Here we find the maximum number of rows that will be transfered.
Dim nl As Integer: nl = wkInput.UsedRange.Rows.Count

'Here we create a few couner variables.
Dim Row As Integer, Col As Integer, i As Integer, j As Integer

'*********Procedure begins here************
Row = 1
Col = 1
For j = 1 To 3
    For i = 1 To nl - 1
        wkDest.Cells(Row, Col).Value = wkInput.Cells(i + 1, 1).Value
        wkDest.Cells(Row, Col + 1).Value = wkInput.Cells(i + 1, j + 1).Value
        Row = Row + 1
    Next i
Next j

'*******Procedure ends here*************
End Sub

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-03-30
    • 2018-06-17
    • 2014-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多