![]() |
Input Box - Type mismatch
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 |
Input Box - Type mismatch
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 -- Gary "Tendresse" wrote in message ... 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 |
Input Box - Type mismatch
FANTASTIC ... it's working perfectly.
Thank you soooo much, GKeramidas :) "GKeramidas" wrote: 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 -- Gary "Tendresse" wrote in message ... 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 |
All times are GMT +1. The time now is 11:12 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com