3

我想删除命名范围 rbTop 和 rbBottom 之间的所有行

Range("rbBottom").Value = ""
Range("rbTop").Select
Do While (Selection.Offset(1, 0).Value <> "")
Selection.Offset(1, 0).EntireRow.Delete
Loop    

这行得通,但我想要一个稍微短一点的方法

Range("rbTop").Select
Do While (Selection.Offset(1, 0).Name <> "rbBottom")  // how to write this line ?
Selection.Offset(1, 0).EntireRow.Delete
Loop
4

1 回答 1

4

没有任何Selector 循环:

Sub Cull()
Dim rng1 As Range
Set rng1 = Range(Range("rbtop"), Range("rbbottom"))
If rng1.Rows.Count > 2 Then rng1.Offset(1, 0).Resize(rng1.Rows.Count - 2, 1).EntireRow.Delete
End Sub
于 2012-09-15T07:05:21.100 回答