0
我已经编写了此代码以删除Excel电子表格的列中的重复行。我不知道如何或者如果可能的话,从函数内部退出while循环。我不想在循环中添加第二个条件(如Counter < 100
),因为我不希望它运行超过需要。从递归函数退出while循环
Sub Deletion()
Dim Cond As Boolean
Dim Counter As Integer
Cond = True
Counter = 2
While Cond = True
RecDel (Counter)
Counter = Counter + 1
Wend
End Sub
Function RecDel(Varii As Integer)
Set CurrentCell = Workbooks("Duplicate.xls").Sheets("Sheet1").Cells(Varii, 2)
If CurrentCell.Value = CurrentCell.Offset(1, 0).Value And CurrentCell.Offset(1, 0).Value <> "" Then
Workbooks("Duplicate.xls").Sheets("Sheet1").Rows(Varii + 1).Delete
RecDel (Varii) 'Repeats deletion until this row and the next row are different
ElseIf CurrentCell.Offset(1, 0).Value = "" Then
Cond = False 'This can't change the global variable and break the loop
Else
End If
End Function
This works。谢谢! – dronae