Find Values in One Cell Then Delete Entire Row

dgr

Board Regular
Joined
Apr 24, 2005
Messages
176
Hello,
I'm using Excel 2013. I'm looking for a VB macro solution.

I want to find Hello in any cell. Then I want to delete (clear contents) that cell & every cell along the same row moving to the right until the end of the worksheet. I want to loop through the entire used range of the worksheet & delete any such occurrence.

Explained in a different way:

Cell D3 contains Hello
Under such circumstances, the macro should delete (clear contents) everything from Cell D3 - XFD3.

This question is a slight variation of a similar question I asked 2 years ago here: http://www.mrexcel.com/forum/excel-...ells-same-row-clear-contents.html#post3957313 Therefore, if you could help me to edit the code here, it would work fine.

Thanks
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Code:
Sub helloFinder()

Dim lastRow As Long, fndHello As Range, lastCol As Long

With Sheets("mySheet")
    lastRow = .UsedRange.Cells.Rows.Count
Set fndHello = .Cells.Find(What:="Hello", searchdirection:=xlNext)

    Do While Not fndHello Is Nothing

    lastCol = .Cells(fndHello.Row, Columns.Count).End(xlToLeft).Column
    .Range(.Cells(fndHello.Row, fndHello.Column), .Cells(fndHello.Row, lastCol)).ClearContents
    Set fndHello = .Cells.FindNext(fndHello)
    
    Loop

End With

End Sub
 
Last edited:
Upvote 0
Did you try this yet?
Thanks for your help, svendiamond. It worked well. This
Code:
searchdirection:=xlNext
did not work so I just replaced it with
Code:
LookIn:=xlValues, LookAt:=xlPart, MatchCase:=False, SearchFormat:=False
& everything worked fine. Thank you once again for your kind assistance. I appreciate it.
 
Upvote 0
Your subject line said:
"Find Values in One Cell Then Delete Entire Row "
Then you said"

"should delete (clear contents) everything from Cell D3 - XFD3.
That would mean do not clear columns A and B values
And it would not delete the row as your title indicated.

If you want to clear always say "Clear" if you want to delete please say "delete".
And when you say clear you need to say clear all or just clear contents.
Thanks.
 
Upvote 0

Forum statistics

Threads
1,223,275
Messages
6,171,123
Members
452,381
Latest member
Nova88

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