我正在执行删除功能,我尝试删除所需的"对象"只要没有或无效的用户输入。
但是,当我这样做时,它不会执行删除操作。
我需要帮助来纠正我的错误!
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
答案 0 :(得分:0)
您的变量(R
和rng
)不一致,您应该使用
If TypeName(R) <> "Range" Then
也就是说,建议您尝试检查有效范围,如下所示:
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