Bur*_*ter 4 excel vba excel-vba delete-row
我正在尝试编写一个宏来删除A列中"True"的所有行.
这是我到目前为止:
Sub deleteBlankRows3()
Dim lastrow as Long
Dim x as Long
lastrow = 4650
For x=8 to x=lastrow
If (Range("A1").Offset(x,0) = True) Then
Range("A1").Offset(x,0).EntireRow.Delete
x = x + 1
End if
Next x
End Sub
Run Code Online (Sandbox Code Playgroud)
我不知道出了什么问题!
我知道你已经得到了你想要的东西.但是,这里仍然使用另一种方法Autofilter.这比循环遍历每一行并检查值要快得多.
Sub Sample()
Dim lastRow As Long
With Sheets("Sheet1")
lastRow = .Range("A" & Rows.Count).End(xlUp).Row
'~~> Remove any filters
.AutoFilterMode = False
'~~> Filter, offset(to exclude headers) and delete visible rows
With .Range("A1:A" & lastRow)
.AutoFilter Field:=1, Criteria1:="TRUE"
.Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Delete
End With
'~~> Remove any filters
.AutoFilterMode = False
End With
End Sub
Run Code Online (Sandbox Code Playgroud)
HTH