work4livinsean
Programmer
Hi, I am a little confused here because my code works the first time the error trap works but the code will not work the second time. I get the error message runtime error 1004. I can type in a number instead of a letter and the error works, but if I do it again it will not work. Basically what I want to do is allow the user to make the same mistake of typing in a number instead of a letter (or vise versa) as many times as he/she does wants to. The reason for this is that I do not want the error message popping up. Can anyone help me with this code or suggest another way of approaching this problem? I would really appreciate it, thanks in advance. Here is my code (basic):
Sub Test()
Dim continue As Boolean
continue = True
Do while continue = True
Dim letCol
letCol = InputBox("Please enter a letter.", "Letter Only")
On Error GoTo AddError
Range(letCol & "12").Select
Dim rowNum
rowNum = InputBox("Please enter a number.", , "Number Only")
On Error GoTo AddError
Range("A" & rowNum).Select
'Code to be executed here
AddError:
Range("A1").Select
Set letCol = Nothing
Set rowNum = Nothing
continue = MsgBox("Would you like to run this macro again?", vbYesNo, "Retry")
If continue = vbYes Then
continue = True
Else
continue = False
End If
Loop
End Sub
Thanks in advance!
Sub Test()
Dim continue As Boolean
continue = True
Do while continue = True
Dim letCol
letCol = InputBox("Please enter a letter.", "Letter Only")
On Error GoTo AddError
Range(letCol & "12").Select
Dim rowNum
rowNum = InputBox("Please enter a number.", , "Number Only")
On Error GoTo AddError
Range("A" & rowNum).Select
'Code to be executed here
AddError:
Range("A1").Select
Set letCol = Nothing
Set rowNum = Nothing
continue = MsgBox("Would you like to run this macro again?", vbYesNo, "Retry")
If continue = vbYes Then
continue = True
Else
continue = False
End If
Loop
End Sub
Thanks in advance!