请教高手解答!运行这段代码,就进入死循环!
运行代码,程序就进入死循环,在334行一直插入行。这是怎么回事?
想要实现的是满足IF条件后,插入一行。再继续判断,直到表结束。
代码如下,请高手指点一下啊!
Sub part1_insert()
Dim i As Variant
i = 2
While Worksheets( "sheet1 ").Range( "A " & i + 1).Value <> " " '未到表尾
If Worksheets( "sheet1 ").Range( "D " & i + 1).Value <> Worksheets( "sheet1 ").Range( "D " & i).Value And Worksheets( "sheet1 ").Range( "O " & i).Value < 6 And Worksheets( "sheet1 ").Range( "O " & i + 1).Value <> Worksheets( "sheet1 ").Range( "O " & i).Value + 1 Then
Worksheets( "sheet1 ").Rows(i + 1 & ": " & i + 1).Select
Selection.insert Shift:=xlDown
End If
i = i + 1
Wend
End Sub
[解决办法]
试试
改:
While Worksheets( "sheet1 ").Range( "A " & i + 1).Value <> " "
为:
While trim(Worksheets( "sheet1 ").Range( "A " & i + 1).Value <> vbnullstring