Find value using inputbox and delete

kevatarvind

Well-known Member
Joined
Mar 3, 2013
Messages
1,047
Hello All,

i am trying to write a code that will find value using input box and if that value find then want to delete that entirerow but my code is not working something wrong i have written can any body pls help me on this to write this code correctly code is below
Code:
Sub Find_DEL()
Dim found As Range
found = Application.Find(What:=InputBox("What To Find", "Find And Delete"), LookIn:=xlValues, lookat:=xlWhole)
If found = Not Nothing Then found.EntireRow.Delete
End Sub

Thanks in Advance
 

Some videos you may like

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.

vds1

Well-known Member
Joined
Oct 5, 2011
Messages
1,194
Try,
Code:
Sub Find_DEL()
Dim found As String
found = InputBox("What To Find", "Find And Delete")
If found <> "" Then Cells.Find(what:=found, Lookat:=xlWhole).EntireRow.Delete
End Sub
 

kevatarvind

Well-known Member
Joined
Mar 3, 2013
Messages
1,047
Try,
Rich (BB code):
Sub Find_DEL()
Dim found As String
found = InputBox("What To Find", "Find And Delete")
If found <> "" Then Cells.Find(what:=found, Lookat:=xlWhole).EntireRow.Delete
End Sub

Thanks for you help but still error in your code below highlighted
Rich (BB code):
Sub Find_DEL()
Dim found As String
found = InputBox("What To Find", "Find And Delete")
If found <> "" Then Cells.Find(what:=found, Lookat:=xlWhole).EntireRow.Delete
End Sub
 

vds1

Well-known Member
Joined
Oct 5, 2011
Messages
1,194
Maybe because you are trying to find a string which is not found.

Try,

Code:
Sub Find_DEL()
On Error GoTo err_desc
Dim found As String
found = InputBox("What To Find", "Find And Delete")
If found <> "" Then Cells.Find(what:=found, Lookat:=xlWhole).EntireRow.Delete
Exit Sub
err_desc:
If Err.Number = 91 Then MsgBox "Value Not found."
End Sub

Here found tries to match the entire cell content. If you need partial cell content to be searched make it Lookat:=xlpart
 

kevatarvind

Well-known Member
Joined
Mar 3, 2013
Messages
1,047
Maybe because you are trying to find a string which is not found.

Try,

Code:
Sub Find_DEL()
On Error GoTo err_desc
Dim found As String
found = InputBox("What To Find", "Find And Delete")
If found <> "" Then Cells.Find(what:=found, Lookat:=xlWhole).EntireRow.Delete
Exit Sub
err_desc:
If Err.Number = 91 Then MsgBox "Value Not found."
End Sub

Here found tries to match the entire cell content. If you need partial cell content to be searched make it Lookat:=xlpart

Thanks a lot VDS1

Its working Perfect like a charm thanks again :)
 

Watch MrExcel Video

Forum statistics

Threads
1,123,535
Messages
5,602,217
Members
414,513
Latest member
junbuggle

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
Top