删除对象所需的错误

我正在执行删除function,我试图删除“所需的对象”,每当没有或无效的用户input。

但是,当我这样做,它不会执行删除操作。

我需要帮助来纠正我的错误!

Sub deletetry2() Dim R As Range On Error Resume Next Set R = Application.InputBox("Select cells To be deleted", , , , , , , 8) On Error GoTo 0 If TypeName(rng) <> "Range" Then MsgBox "Cancelled", vbInformation Exit Sub Else R.delete End If End Sub 

你variables( Rrng )不一致,你应该使用
If TypeName(R) <> "Range" Then

这就是说,build议你尝试检查一个有效的范围如下:

  Dim R As Range On Error Resume Next Set R = Application.InputBox("Select cells To be deleted", , , , , , , 8) On Error GoTo 0 If R Is Nothing Then MsgBox "Cancelled", vbInformation Exit Sub Else R.Delete End If