本帖最后由 adders 于 2012-3-5 22:00 编辑
For Ro = 1 To lstRo
If Application.CountA(Area_.Rows(Ro)) = 0 Then
If Rng1 Is Nothing Then
Set Rng1 = Rows(Ro)
Else
Set Rng1 = Union(Rng1, Rows(Ro))
End If
End If
Next
如果以上红色部分从来没有成立过,即Application.CountA(Area_.Rows(Ro)) 从来就没有=0时, Rng1就从来不会被定义,之后
Rng1.EntireRow.Delete 就会出错
同理,以下红色部分如果从来未成立,则Rng2就不会被定义,之后的Rng2.EntireColumn.Delete就会出错
For Col = 1 To lstCol
If Application.CountA(Area_.Columns(Col)) = 0 Then
If Rng2 Is Nothing Then
Set Rng2 = Columns(Col)
Else
Set Rng2 = Union(Rng2, Columns(Col))
End If
End If
Next
解决办法:在Rng1.EntireRow.Delete这一行上面加一行: On Error Resume Next