关于错误'1004'的任何建议:范围类的删除方法失败?简单的删除按钮不起作用

问题描述

问题:我有一个删除按钮,可以在一种表单上使用,但是当更改相同的代码以反映不同的工作表时,会引发错误“范围类的删除方法失败”

在遵循了在线教程之后,我设法创建了一个功能正常的表单。因此,我决定要在同一工作簿的新工作表上复制类似的表格。

在这种情况下,我创建了一个新模块并复制了代码,并更改了代码以反映工作表的名称。“ paptops”。

我复制并更改了用于遍历列表框条目的函数名称,最初在原始模块上为“ Selected_List”,为此表创建了一个新模块,并将其称为“ Lap_List”函数

奇怪的是,我的“编辑”按钮工作正常。

以下是用于尝试删除代码

Private Sub Btn_Delete_Click()

''''' If no Option Selected displays a Message '''

 If Lap_List = 0 Then

      MsgBox "No row is selected.",vbOKOnly + vbinformation,"Delete"
      Exit Sub
 End If

  '''' If option is Selected peresnt Option Box '''

 Dim imsg As VbMsgBoxResult

imsg = MsgBox("Do you want to delete the selected record?",vbYesNo + vbQuestion,"Confirmation")

If imsg = vbNo Then Exit Sub

   ''''' If yes then delete the selected row from ListBox and cells on sheet ''''

ThisWorkbook.Sheets("Laptops").Rows(Lap_List + 1).Delete '''' Error 1004 but worked fine on another form''''
    
Call Reset

MsgBox "Selected record has been deleted.","Deleted"



End Sub

以及用于引用的功能

Function Lap_List() As Long

 Dim iRow As Long

 Lap_List = 0

   For iRow = 0 To Frm_Laptops.Lstbx_Laptops.ListCount - 1
    
   If Frm_Laptops.Lstbx_Laptops.Selected(iRow) = True Then
    
    Lap_List = iRow + 1
    Exit For

    End If
    
    Next iRow


End Function

我真的很坚持这一点,当我尝试将删除代码更改为range.end(xlup)等的变体时,它也遇到了同样的问题。

有什么建议吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)