0

我有一长串按以下方式在列中结构化的数据:

miR-4782-5p
miR-4740-3p
miR-3173-5p
miR-617/2340
miR-1260/1260b/1391
miR-4642
miR-1392

我需要将其转换为以下格式:

miR-4782-5p
miR-4740-3p
miR-3173-5p
miR-617
miR-2340
miR-1260
miR-1260b
miR-1391
miR-4942
miR-1392

本质上,我只想将按括号分组的数据分开,并使其成为自己的项目,同时继续列表。

想法?

4

1 回答 1

1

这段代码应该做你需要的

Sub SplitCellsAndExtend_Olddasgf()
'takes cells with inside line feeds and creates new row for each.
'reverses merge into top cell.

Dim strCell As String, lastRow As Long, i As Long, j As Long, sPrefix As String
Const sSplitOn As String = "/"

application.ScreenUpdating = False
lastRow = Cells(Rows.Count, 1).End(xlUp).Row

    For i = lastRow To 1 Step -1
        strCell = Cells(i, 1)
        j = 0

        Do While InStr(1, strCell, sSplitOn) > 0
            Rows(i + j + 1).Insert
            sPrefix = Left(strCell, InStr(strCell, "-"))
            strCell = Right(strCell, Len(strCell) - InStr(1, strCell, sSplitOn))
            Cells(i + j, 1) = Left(Cells(i + j, 1).Value, InStr(1, Cells(i + j, 1), sSplitOn) - 1)
            strCell = sPrefix & strCell
            Cells(i + j + 1, 1).Value = strCell
            j = j + 1
        Loop
    Next
application.ScreenUpdating = True
End Sub
于 2012-11-08T20:51:06.730 回答