Stop error code from executing

  • Thread starter Thread starter stewart
  • Start date Start date
S

stewart

I have a userform that contains a textbox. The user types in the name
of the person they are removing from the sheet and the VB code
searches for that name, deletes it and hides the row. I want to add
code that will display a msgbox ifthey type in a name wrong or one
that doesn't exist. However, even if there is no error it still runs
the msgbox. How do i tell vb to skip the msgbox if there is no
error. My code is below.

Private Sub btnRem_Click()
Sheets(2).Cells(1, 1).Activate
On Error GoTo b
Cells.Find(What:=txtName.Value, After:=ActiveCell,
LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows,
SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Selection.Value = ""
Sheets(Array("Payroll Info", "Store Schedule")).Select
Selection.EntireRow.Hidden = True
Sheets(1).Activate
Selection.EntireRow.Hidden = True
b: MsgBox "That associate does not exist. Please double check the
spelling as it appears on the schedule and try again", vbExclamation
txtName.Value = ""
Sheets(2).Activate
 
Hi

If you exit the sub before the error handling runs it should work.
i.e. add the line noted below.

Selection.EntireRow.Hidden = True

exit sub

b: MsgBox "That associate does not exist. Please double check
the

hope this helps
 

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

Back
Top