我正在尝试创建一个宏,它将帮助我查找“,”并且如果找到它。它将复制整行而没有第一个“,”它看到并在下面插入另一行。
例如。 9877352,9877354
它会将一行变成两行,并且信息相同。
只有不同的是9877352将在一行上,然后9877354将在同一个表的下一行。
代码:
Sub comma()
Dim i As Long
Dim text As String
Dim myCell As Range
FinalRow = Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To FinalRow
thisvalue = Cells(i, 5).Value
If thisvalue Like "*,*" Then
Cells(i, 5).EntireRow.Copy
'I don't know what to put here
'Cells(i, 5).EntireRow.Insert
End If
Next i
End Sub
答案 0 :(得分:0)
如果单元格中有两个以上的逗号,我会使用一个数组。该列是否会发生变化?如果不是,我会做这样的事情......
Sub comma()
Dim Order As Variant, cell As Range
For Each cell In Range("E:E") 'Enter static column reference here
If cell.Value Like "*,*" Then
Order = Split(cell, ",")
For i = LBound(Order) To UBound(Order)
If i = 0 Then
cell.Value = Order(i)
Else
cell.EntireRow.Copy
cell.EntireRow.Insert
Range("E" & cell.Row) = Trim(Order(i))
End If
Next i
Else
End If
Next cell
End Sub