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

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

Greg Truby

MrExcel MVP
Joined
Jun 19, 2002
Messages
10,022
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
 
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,167,954
Messages
5,856,486
Members
431,817
Latest member
db74

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