我通过以下方式在列中构建了一长串数据:
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
基本上,我只想分开用括号分组的数据,并在继续列表的同时将其作为自己的项目。
思想?
答案 0 :(得分: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