错误1004范围类的删除方法失败

当我开始一个新的分裂时,我想删除特定工作表之间的旧数据。 (在绿色和红色之间)。 不幸的是我得到这个错误消息,并不能找出我做错了什么。

“错误1004范围类的删除方法失败”

请帮忙 ! 谢谢。

'----------------------------- Sub Test() '----------------------------- Dim ws As Worksheet Dim lRow As Long, lCol As Long Dim Rng As Range Dim beginIdx As Integer, endIdx As Integer '-- Get the 'Green' and 'Red' indexses in the active workbook . beginIdx = ActiveWorkbook.Sheets("Green").Index + 1 endIdx = ActiveWorkbook.Sheets("Red").Index - 1 '-- Delete old data between 'Green' and 'Red' tabs For J = beginIdx To endIdx '-- Set this to the relevant worksheet Set ws = ActiveWorkbook.Sheets(J) With ws '-- Get the last row and last column lRow = .UsedRange.SpecialCells(xlCellTypeLastCell).row lCol = .Cells(1, .Columns.Count).End(xlToLeft).Column '-- Set the sheet range to delete old data leaving the headings intact Set Rng = .Range(.Cells(2, 1), .Cells(lRow, lCol)) Application.DisplayAlerts = False ' Get rid of pop-up message With Rng '-- Now delete the old data from the sheet .EntireRow.Delete End With Application.DisplayAlerts = True ' Back to normal End With Next J End Sub 

现在这个工作。 我只需要包括:
*如果语句检查lRow值大于2
*将范围单元格值从2 – > 3(设置Rng = .Range(.Cells(3,1)…)

 '----------------------------- Sub Test() '----------------------------- Dim ws As Worksheet Dim lRow As Long, lCol As Long Dim Rng As Range Dim beginIdx As Integer, endIdx As Integer '-- Get the 'Green' and 'Red' indexses in the active workbook . beginIdx = ActiveWorkbook.Sheets("Green").Index + 1 endIdx = ActiveWorkbook.Sheets("Red").Index - 1 '-- Delete old data between 'Green' and 'Red' tabs For J = beginIdx To endIdx '-- Set this to the relevant worksheet Set ws = ActiveWorkbook.Sheets(J) With ws '-- Get the last row and last column lRow = .UsedRange.SpecialCells(xlCellTypeLastCell).row lCol = .Cells(1, .Columns.Count).End(xlToLeft).Column '-- Set the sheet range to delete old data leaving the headings intact If lRow > 2 Then Set Rng = .Range(.Cells(3, 1), .Cells(lRow, lCol)) Application.DisplayAlerts = False ' Get rid of pop-up message With Rng '-- Now delete the old data from the sheet .EntireRow.Delete End With End If Application.DisplayAlerts = True ' Back to normal End With Next J End Sub