Find value using inputbox and delete

kevatarvind

Well-known Member
Joined
Mar 3, 2013
Messages
1,047
Office Version
  1. 365
Platform
  1. Windows
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
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce

vds1

Well-known Member
Joined
Oct 5, 2011
Messages
1,200
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
Office Version
  1. 365
Platform
  1. Windows
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,200
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
Office Version
  1. 365
Platform
  1. Windows
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 :)
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,675
Messages
5,838,716
Members
430,566
Latest member
ChanchalSingh

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