我用一些标准填充数字数组,然后我想要删除的是该区域中的所有行。
基本上我会浏览一个列,如果在该特定行中,此列中的单元格符合条件,我将该行号添加到数组中。完成所有行后,我想删除所有行号。
我无法弄清楚如何一次删除所有行,因为很明显,如果我一次删除一行,则行号会随着前一个或下一个的删除而改变。因此,我想一起选择所有行,然后一次只调用所有行上的Delete命令。任何想法?
答案 0 :(得分:7)
Sub Tester()
Dim arr
arr = Array(3, 5, 7, 9)
ActiveSheet.Range("A" & Join(arr, ",A")).EntireRow.Delete
End Sub
答案 1 :(得分:3)
向后遍历你的行。
类似的东西:
Sub tester()
'setting ScreenUpdating false makes this go faster...
Application.ScreenUpdating = False
Dim i As Integer
'go through all rows starting at last row
For i = Range("A1:E5").Rows.Count To 1 Step -1
'check if you need to delete them (you will want to update this)
If Cells(i, 1).Value = "Delete this row!" Then
Rows(i).Delete
End If
Next i
Application.ScreenUpdating = True
End Sub
答案 2 :(得分:1)
这是一个简单的问题:
If Range("B1") <> "" Then ' Range that bears the array of cell.addresses....
ar = Array(Range(Range("B1").Cells))
For Each a In ar
a.EntireRow.ClearContents
Next
Range("B1").ClearContents
End If