gpt4 book ai didi

excel - For Loop 留下不需要的行

转载 作者:行者123 更新时间:2023-12-04 21:53:38 27 4
gpt4 key购买 nike

...因为该行仅评估一次,并且调用下一行进行评估。但是下一行现在是上一行。我该如何解释?

For i = 5 To Range("A" & "65536").End(xlUp).Row Step 1
If Application.WorksheetFunction.CountIf(Range("A" & i), "#N/A") = 1 Then
Range("A" & i).EntireRow.Delete
End If
Next i

最佳答案

您可以使用 Union 一次性删除所有行。 .像这样:

Sub test()
Dim i As Long
Dim deleteRange As Range

For i = 5 To Range("A" & "65536").End(xlUp).Row Step 1
If Application.WorksheetFunction.CountIf(Range("A" & i), "#N/A") = 1 Then
If deleteRange Is Nothing Then
Set deleteRange = Range("A" & i).EntireRow
Else: Set deleteRange = Union(deleteRange, Range("A" & i).EntireRow)
End If
End If
Next i

deleteRange.Delete
End Sub

关于excel - For Loop 留下不需要的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49281126/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com