Мне нужно сделать следующее:
У меня есть таблица, в которой 13-й столбец содержит такие строки, как
acbd,ef,xyz
qwe,rtyu,tqyuiop
И что я хочу создать новые строки для того, чтобы отделить эти значения:
acbd
ef
xyz
qwe
rtyu
tqyuiop
То есть теперь у меня будет 6 строк вместо 2, и вся остальная информация о ячейках останется прежней (то есть все другие значения строки будут повторяться во всех новых строках).
Я попробовал следующее:
Sub test()
Dim coma As Integer
Dim finalString As String
Set sh = ActiveSheet
For Each rw In sh.Rows
* If find a coma, then copy the row, insert a new row, and paste in this new row*
If InStr(1, sh.Cells(rw.Row, 13).Value, ",") Then
Rows(rw.Row).Copy
Rows(rw.Row).insert shift:=xlShiftDown
Rows(rw.Row).PasteSpecial xlPasteValues
* Now it will look for the position of the comma and assign
to finalString what's before the comma, and assign to mod String
what's after the comma *
coma = InStr(1, sh.Cells(rw.Row, 13).Value, ",")
finalString = Left(sh.Cells(rw.Row, 13).Value, coma - 1)
modString = Right(sh.Cells(rw.Row, 13).Value, Len(sh.Cells(rw.Row, 13).Value) - coma)
* Replace the values: *
sh.Cells(rw.Row, 13).Value = modString
sh.Cells(rw.Row - 1, 13).Value = finalString
End If
Next rw
MsgBox ("End")
End Sub
Этот код работает отлично, за исключением того, что для таблиц с 400 строками требуется 15 + -5 секунд.
Мне бы хотелось несколько советов о том, как улучшить производительность этого. Спасибо!