0
Sub project()
Dim a As Long
Dim rKill As Range
a = 3
Do
If Abs(Cells(a - 1, 7).Value - Cells(a, 7).Value) > 5 And Abs(Cells(a + 1, 7).Value - Cells(a, 7).Value) > 5 Then
If rKill Is Nothing Then
Set rKill = Rows(a)
Else
Set rKill = Union(rKill, Rows(a))
End If
End If
a = a + 2
Loop Until Cells(a, 7).Value = ""
rKill.EntireRow.Delete
End sub
我想删除多行,要做到这一点,我设置范围rKill和rKill是我要删除的所有行的联合。不过,我有以下问题:Excel VBA删除行对象变量或与块变量未设置
Object Variable or With block variable not set
在倒数第二行:
rKill.EntireRow.Delete
我想是因为我暗淡rKill的范围内,我想设置的行成使其应用范围这个错误,但我试过这个:
Set rKill = Rows (a). Range
Else
Set rKill = Union (rKill, Rows (a)).Range
但仍然无法正常工作。
尝试'如果不rKill是Nothing然后rKill.EntireRow.Delete'。 – Fadi
您想要指定您正在使用的工作表。而不是“行(a)”,使用“表格(”mySheet“)。行(a)” – OpiesDad