Find and Delete Option

torweb

Board Regular
Joined
Dec 1, 2003
Messages
136
I'm trying to give my user the option of finding and deleting a row based on thier search criteria. The problem I've run into is it will only delete the specific cell where the search term was located. I would like it to delete the whole range within the row. Here's a copy of my code so far.

Sub findandkill()

Dim x As Variant
Set x = Cells.Find(What:=InputBox("Please enter your search criteria", "Search"), LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByColumns)
If Not x Is Nothing Then
x.Activate
Else
MsgBox "Not found."
End If

Sheets("Journal Entry").Unprotect "password"
Selection.ClearContents
Sheets("Journal Entry").Protect "password"

End Sub

Any pointers on how I can set the number of cells within the row to clear?

Thanks in advance.
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Delete? or Clear? Given your code - I'm going to assume you meant clear.

Just go: Selection.EntireRow.ClearContents (or use .Clear if you want to wipe out formats too)

FYI - you don't need the .Activate bit (unless you want the user to move to the area cleared). You could just go

Code:
If not x is nothing then
  'unprotect
    x.EntireRow.ClearContents
  'protect
Else

If you don't want to clear the entire row you can always use Resize and or Offset, i.e. to clear from cell x through 19 columns to the right of x use x.Resize(1,20).ClearContents
 
Upvote 0

Forum statistics

Threads
1,215,036
Messages
6,122,794
Members
449,095
Latest member
m_smith_solihull

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