gpt4 book ai didi

excel - 将单元格中的多个条目转换为多行

转载 作者:行者123 更新时间:2023-12-04 21:16:30 25 4
gpt4 key购买 nike

我有一个包含乐队名称及其流派的 excel 文件。

A 列:乐队名称。 B栏:流派。

b 列可能包含多个条目,例如“pop/rock”。我想把它分成两行。

例子:

  • [1] 真棒乐队 |流行/摇滚

  • 将转变为
  • [1] 真棒乐队 |流行
  • [2] 真棒乐队 |摇滚

  • 我将如何在 excel 中实现这一点?有什么线索吗?提前致谢。

    最佳答案

    尝试写像@John Dirk Morrison 这样的东西,允许两种以上的流派。但不适用于选择,仅适用于 Sheet1 上的 A 列和 B 列。

    Sub BandSplit()
    Dim Sheet As Worksheet: Set Sheet = ThisWorkbook.Worksheets("Sheet1")
    Dim Genre() As String
    Dim Count As Integer
    Dim Index As Integer
    Dim First As Boolean
    Dim Row As Integer: Row = 2 ' Exclude Header Row

    Do
    Genre = Split(Sheet.Cells(Row, 2), "/")
    Count = UBound(Genre)
    First = True
    If Count > 0 Then
    Index = 0
    Do
    If First = True Then
    Sheet.Cells(Row, 2).Value2 = Genre(Index)
    First = False
    Else
    Sheet.Rows(Row).EntireRow.Insert (xlShiftDown)
    Sheet.Cells(Row, 1).Value2 = Sheet.Cells(Row + 1, 1).Value2
    Sheet.Cells(Row, 2).Value2 = Genre(Index)
    End If
    Index = Index + 1
    If Index > Count Then
    Exit Do
    End If
    Loop
    End If
    Row = Row + 1
    If Sheet.Cells(Row, 1).Value2 = "" Then
    Exit Do
    End If
    Loop
    End Sub

    关于excel - 将单元格中的多个条目转换为多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27564766/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com