B*******e 发帖数: 3882 | 1 You have to consider that the row numbers will change after you delete the r
ows in the first round of the loop.
Here is my code:
Sub DelRows()
'
' Delete Rows in Excel , Macro
'
'
Dim InitialRow(), nRow
Dim DelRange As Range
InitialRow = Array(10, 100, 140) 'Edit or Add here
Set DelRange = Rows(InitialRow(0))
For Each nRow In InitialRow
Set DelRange = Application.Union(DelRange, Range(Rows(nRow), Rows(nR
ow + 19)))
Next
DelRange.Select
Selection.Dele |
|
B*******e 发帖数: 3882 | 2 你在 Rows 前面加上 ActiveSheet. 试试。也就是改成(Fishboy 的code 应该也是这个
问题):
Sub DelRows()
'
' Delete Rows in Excel , Macro
Dim InitialRow(), nRow
Dim DelRange As Range
InitialRow = Array(240, 100, 10) 'Edit or Add here
Set DelRange = ActiveSheet.Rows(InitialRow(0))
For Each nRow In InitialRow
Set DelRange = Union(DelRange, Range(ActiveSheet.Rows(nRow), ActiveS
heet.Rows(nRow + 19)))
Next
DelRange.Select
Selection.Delete Shift:=xlUp
End Sub |
|
h**h 发帖数: 7 | 3 运行了这个代码.从后向前删除。其中 InitialRow = Array(240,100,10)。结果显示出
错信息:Method 'Rows' of object'_ Global' failed. Debug 发现 下列代码出错:
Set DelRange = Rows(InitialRow(0))。不知如何解决?谢谢。
r |
|