Sub test()
Dim a() As String
dim col as double
col = 1'第几列 1表示A列 依此类推
For i = 1 To 65536
If Cells(i, col) = "" Then Exit For
a = Split(Cells(i, col), "/")
If UBound(a) >0 Then
For j = 0 To UBound(a)
If a(j) = "" Then Exit For
rw = i + j
If rw <>i Then Range(rw &":" &rw).Insert
Cells(rw, col) = Left(a(0), Len(a(0)) - Len(a(j))) &a(j)
Next
End If
i = i + UBound(a)
Next
End Sub
如果是你的效果
Sub test()
Dim a() As String
dim col as double
col = 1'第几列 1表示A列 依此类推
For i = 1 To 65536
If Cells(i, col) = "" Then Exit For
a = Split(Cells(i, col), "/")
If UBound(a) >0 Then
For j = 0 To UBound(a)
If a(j) = "" Then Exit For
rw = i + j+1
Range(rw &":" &rw).Insert
Cells(rw, col) = Left(a(0), Len(a(0)) - Len(a(j))) &a(j)
Next
End If
i = i + UBound(a)
Next
End Sub
首先在类别列查找"五金",如果找到,然后从从此行开始向下循环,(可以用for each 在找到的单元格到此列的最后一个单元格),在循环体中用if进行测试B列单元格的内容,如果是"五金",则继续向一行,如果不是,则表示已经到末尾了,现在可以在此插入下行.将你的内容分别输入到对应的单元格中即可.如果没有找到"五金",那么你要么在最后追加,要么在第一行之前插入一行,这个就看你的个人意思了.
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)