为什么popup这个“范围类的删除方法失败”错误?

我想弄清楚为什么这个“范围类的删除方法”错误popup。 当这个macros运行时,并不总是会发生,这使得它更加复杂。

有人可以解释吗?

Sub ResetSheet() If WindowsOS Then '*******************************************************************************************************' 'Resets the Data sheet. Called by the resetSheetButton procedure (located in module: m7_Macros1_5). ' 'Also called by the OkCommandButton_Click procedure in the OnOpenUserForm form. ' '*******************************************************************************************************' Application.EnableEvents = False Sheet4.Visible = True Sheet4.Activate Sheet4.Select Sheet4.Rows("2:101").Select Selection.Copy 'TC Edit Sheet1.Activate Sheet1.Range("A2").PasteSpecial (xlPasteAll) 'Sheet1.Paste Sheets("Data").Select Sheet1.Rows("102:10000").EntireRow.Delete Sheet4.Visible = False 'TC Edit 2.0 - Adding code to reset the exception checkboxes If WindowsOS Then Call resetCheckBoxes End If Application.EnableEvents = True 

这是导致错误的macros代码(有时)

这是popup的错误

尝试使用下面的简化代码

 Sub ResetSheet() 'If WindowsOS Then Application.EnableEvents = False With Worksheets("Sheet4") .Visible = True .Rows("2:101").Copy Worksheets("Sheet1").Range("A2") End With With Worksheets("Sheet1") .Rows("102:101").EntireRow.Delete End With Worksheets("Sheet4").Visible = False If windowsOS Then Call resetCheckBoxes End If Application.EnableEvents = True End Sub