【问题标题】:Several data series in the same column to multiples columns同一列中的多个数据系列到多列
【发布时间】:2015-07-06 14:04:08
【问题描述】:

我有一个 excel 文件,在同一列中有多个系列,我希望每个系列放在一个单独的列中

源表:

A          | B
-----------|---------
Series 1.1 | Series 3.1
Series 1.2 | Series 3.2
Series 1.3 | Series 3.3
           |         
           |         
Series 2.1 | Series 4.1
Series 2.2 | Series 4.2
Series 2.3 | Series 4.3

结果表:

A          | B          | C          |D
-----------|------------|------------|-----------
Series 1.1 | Series 2.1 | Series 3.1 | Series 4.1 
Series 1.2 | Series 2.2 | Series 3.2 | Series 4.2 
Series 1.3 | Series 2.3 | Series 3.3 | Series 4.3 

有什么建议吗?

【问题讨论】:

  • 请查看以下编辑,我假设您希望在列中遇到一个或多个空白单元格时创建一个新列。

标签: excel multiple-columns series vba


【解决方案1】:

您可以尝试下面的代码将一列中的数据拆分为多列,拆分数据基于该列上的空白单元格。 (对于多列可以再次调用该模块)

下面的代码从 Sheet1 中读取单元格:Column('A'):读取 500 行

Public Sub break_data()

Dim row As Integer: row = 500      'Number of rows to read on a column

Dim wks As Object                  'Source Sheet
Set wks = ThisWorkbook.Sheets("Sheet1")

Dim wkr As Object                  'Result Sheet
Set wkr = ThisWorkbook.Sheets("Sheet2")

Dim i As Integer: i = 1
Dim j As Integer: j = 1             'Column that you want to split

Dim x As Integer: x = 1
Dim y As Integer: y = 1

Do While (i <= 500)
    If (Len(Trim(wks.Cells(i, j).Value)) > 0) Then
        wkr.Cells(x, y).Value = wks.Cells(i, j).Value
        x = x + 1
    ElseIf (Len(Trim(wks.Cells(i, j).Value)) = 0) And (x <> 1) Then
        x = 1
        y = y + 1
    End If
    i = i + 1
Loop
End Sub

来源:

结果:(运行vba后)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-07
    • 1970-01-01
    相关资源
    最近更新 更多