从第二行开始,向下按照B列的值循环插入数据
如果符合条件1,或者条件2,则将数据集合1s的数据逐个插入下面的单元格中,
如果符合条件2,或者条件3,或者条件4,则将数据集合2s的数据逐个插入下面的单元格中
Sub 根据条件循环插入数据()
i = 2
数据集合1s = Array("数据1-1", "数据1-2", "数据1-3", "数据1-4")
数据集合2s = Array("数据2-1", "数据2-2", "数据2-3", "数据2-4", "数据2-5", "数据2-6", "数据2-7")
Do
Select Case Cells(i, "B")
Case "条件1", "条件2"
For Each 数据集合1 In 数据集合1s
Rows(i + 1).Insert shift:=xlShiftDown
Cells(i + 1, "C") = Cells(i, "C")
Cells(i + 1, "B") = Cells(i, "B")
Cells(i, "A") = 数据集合1
i = i + 1
Next 数据集合1
Rows(i).Delete
Case "条件1", "条件2","条件3"
For Each 数据集合2 In 数据集合2s
Rows(i + 1).Insert shift:=xlShiftDown
Cells(i + 1, "C") = Cells(i, "C")
Cells(i + 1, "B") = Cells(i, "B")
Cells(i, "A") = 数据集合2
i = i + 1
Next 数据集合2
Rows(i).Delete
End Select
Debug.Print i
If i Mod 2000 = 0 Then
Debug.Print i
End If
Loop While Cells(i, "C") <> ""
End Sub