Firecop1348
Board Regular
- Joined
- Oct 24, 2009
- Messages
- 101
I have a macro that will find a sheet in my workbook. It works great the first time it runs , If I put in a name of a sheet that is not in my workbook it sayes "no record found for (fName) try again" I hit try again and it works but if it doesent find the sheet name the second time I get a Run time error '9' subsript out of range. I do not understand why it will work fine the first time but not the second time. I need it to go back into the "No record found for (fname) try again" so I can keep trying until I find the sheet name.
Sub FindName()
here:
On Error GoTo errhandler
fname = InputBox("please enter the " & _
"name to find.", "Search For")
ActiveWorkbook.Sheets(fname).Activate
Exit Sub
errhandler:
noFind = MsgBox("No record found for " & _
UCase(fname), vbYesNo, "Try Again")
Select Case noFind
Case Is = vbYes
GoTo here
Case Is = vbNo
End Select
End Sub
Sub FindName()
here:
On Error GoTo errhandler
fname = InputBox("please enter the " & _
"name to find.", "Search For")
ActiveWorkbook.Sheets(fname).Activate
Exit Sub
errhandler:
noFind = MsgBox("No record found for " & _
UCase(fname), vbYesNo, "Try Again")
Select Case noFind
Case Is = vbYes
GoTo here
Case Is = vbNo
End Select
End Sub