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

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
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,998
Messages
6,122,638
Members
449,093
Latest member
Ahmad123098

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