gpt4 book ai didi

vba - 为什么会弹出这个 "Delete Method of Range class failed"错误?

转载 作者:行者123 更新时间:2023-12-04 20:12:05 26 4
gpt4 key购买 nike

我试图弄清楚为什么会弹出这个“范围类的删除方法”错误。当这个宏运行时,它并不总是发生,这使得它更加令人困惑。

有人可以解释一下吗?

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

This is the macro code that causes the error (sometimes)

This is the error pop-up

最佳答案

尝试使用以下简化代码

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

关于vba - 为什么会弹出这个 "Delete Method of Range class failed"错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37061109/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com