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

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
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
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0
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 :)
 
Upvote 0

Forum statistics

Threads
1,214,965
Messages
6,122,499
Members
449,089
Latest member
Raviguru

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