代码在这里:
Sub deleterow2()
Dim a As Integer
Dim n As Integer
Dim c As Integer
LastRow = Range("F" & Rows.Count).End(xlUp).Row
For n = 0 To LastRow
a = 1
c = 0
Do Until c = 1
Cells(n + a, 6).Select
If Selection.value = Cells(n, 6) And Selection.value > 30 Then
Selection.EntireRow.Delete
Else
c = 1
End If
a = a + 1
Loop
Next n
End Sub
这怎么了?
答案 0 :(得分:1)
请参见下面的更正代码...而不是将n
从0开始,而将a
从0开始。另外,请避免使用.Select
所有...并且您应该尝试完全声明您的范围:
Sub deleterow222()
Dim lastRow As Long, R As Long
Dim ws As Worksheet: Set ws = ActiveWorkbook.ActiveSheet
Dim idColumn as Long: idColumn = 6
Dim diffColumn as Long: diffColumn = 19
lastRow = ws.Range("F" & ws.Rows.Count).End(xlUp).Row
For R = lastRow To 2 Step -1
With ws
If .Cells(R, idColumn) = .Cells(R - 1, idColumn) And .Cells(R, diffColumn) > 30 Then
.Cells(R, idColumn).EntireRow.Delete
End If
End With
Next R
End Sub
答案 1 :(得分:1)
一些提示:
n = 0
,因为会创建错误。行从1开始。For n = LastRow To 1 Step -1
For Loop
声明变量As Long
。Array
。.Select
来避免With Statement
With ThisWorkbook.Worksheets("Sheet1")
,然后使用.Cells(n + A, 6).Value
Do Until
也应该从高到低开始,因为您从下到上。答案 2 :(得分:0)
sub deleterow2()
Dim lastRow As Long,R As Long 昏暗的ws作为工作表:设置ws = ActiveWorkbook.ActiveSheet
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//ul[@class='mailler']//li[contains(@class, 'mail')]//a"))).click()
结束子