Error handling a macro to delete a row

Bradzo

New Member
Joined
Nov 15, 2017
Messages
11
Hi all,

I have a problem where I have the below code deletes the upper most empty row if no name or an incorrect name is entered into the InputBox?

I thought I may overcome this with If searchthis = "" Then Exit Sub but it doesn't seem to work. Help would be appreciated.

Thanks.



Sub Button4_Click()
'Archive person X Dock
Dim searchthis

searchthis = InputBox("Enter employee NAME to search.", "Property Search")

If searchthis = "" Then
Exit Sub
End If

On Error GoTo errorhandler

Application.ScreenUpdating = False

ActiveSheet.Range("b:b").Select
Selection.Find(What:=searchthis, After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlNext).Activate
ActiveCell.Select


Rows(ActiveCell.Row).Delete Shift:=xlUp

Application.ScreenUpdating = True

Exit Sub
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Try using
You also didn't have a error handler for the error line to go to
VBA Code:
Sub Button4_Click()
Dim searchthis As String
On Error GoTo errorhandler
searchthis = InputBox("Enter employee NAME to search.", "Property Search")
If searchthis = "" Then Exit Sub
Application.ScreenUpdating = False
ActiveSheet.Range("b:b").Find(What:=searchthis, After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlNext).Activate
Rows(ActiveCell.Row).Delete
Application.ScreenUpdating = True
Exit Sub
errorhandler:
MsgBox "Nothing found"
Application.ScreenUpdating = True
Exit Sub
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,493
Messages
6,125,119
Members
449,206
Latest member
burgsrus

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top