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

我有一个带的名称和他们的stream派的Excel文件。

A栏:乐队名。 B栏:stream派。

b列可能包含多个条目,如“stream行/摇滚”。 我想分裂成两行。

例:

  • [1] Awesomeband | stream行摇滚

将被转化为

  • [1] Awesomeband | stream行的
  • [2] Awesomeband | 岩

我怎么会意识到,在Excel中? 任何线索? 提前致谢。

去写一些像约翰·德里克·莫里森(John Dirk Morrison)的东西,就可以有两种以上的stream派。 并不适用于select,只是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 

突出显示列B并运行此VBA应该做的伎俩:

 Sub bandsplit() Dim c As Range Dim splitv() As String For Each c In Selection splitv = Split(c.Value, "/") If UBound(splitv) > 0 Then c.EntireRow.Insert c.Offset(-1, 0).Value = splitv(1) c.Offset(-1, -1).Value = c.Offset(0, -1).Value c.Value = splitv(0) End If Next c End Sub 

它只限于2种stream派,但是你可以用它来增加更多。

为了@ Navneet的企图,分裂为C1:D2放入=A$1并复制到A2。 在D1:

 =LEFT(B1,FIND("/",B1)-1) 

在D2中:

 =MID(B1,FIND("/",B1)+1,LEN(B1)) 

我假设Awesomeband | Pop | Rock存储在A1位置
对于Awesomeband | Pop =LEFT(A1,15)
For Awesomeband | Rock = =LEFT(A1,12)&""&(RIGHT(A1,4))
我认为这应该工作。