Input Box - Type mismatch

T

Tendresse

Hello all, I'm not sure what i am doing wrong and need your help please.
I wrote a code that asks the user for the row number they wish to delete.
But i keep getting the following error message:
Run-Time error '13' - Type mismatch.

Here is the code i wrote:

Sub Del_Row()

' Ask user for the row number
Dim RowToDelete As Long
RowToDelete = InputBox( _
Prompt:="Please enter the row number you wish to delete, eg: 23", _
Title:="Which Row Do You Wish to Delete?")

' exit sub if user presses 'cancel'
If RowToDelete = "" Then
Exit Sub
End If

if RowToDelete > 20 then
Rows(RowToDelete).delete
Else
MsgBox "Sorry! You cannot delete This row."
End If

End Sub

When i run the macro, i get the inputbox asking me for the number but when i
press cancel or enter a number i keep getting the above error message. Any
ideas?
I'm using Excel 2003
Thanks in advance
Tendresse
 
G

GKeramidas

you can give this a try:

Sub Del_Row()

' Ask user for the row number
Dim RowToDelete As Long
RowToDelete = Application.InputBox( _
Prompt:="Please enter the row number you wish to delete, eg: 23", _
Title:="Which Row Do You Wish to Delete?", Type:=1)

' exit sub if user presses 'cancel'
If RowToDelete = 0 Then
Exit Sub
End If

If RowToDelete > 20 Then
Rows(RowToDelete).EntireRow.Delete
Else
MsgBox "Sorry! You cannot delete This row."
End If

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top