Selecting a cell with a value and deleting it along with 4 cells above

kknb4591

New Member
Joined
Aug 25, 2011
Messages
10
Hi,

I have a piece of code which searches for the phrase "Global" in a sheet and then deletes that cell and the 4 cells above it:

Cells.Find(What:="Global", After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Activate
Range("A1625").Select
Range("A1621:A1625").Select
Range("A1625").Activate
Selection.ClearContents

However, how can I get it to automatically find the word delete the cell and then delete the 4 cells above? As the word "Global" will not always be in cell A1625. It will, however, always be in column A if that helps.

Would greatly appreciate assistance with this.
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Try:

Code:
    Cells.Find(What:="Global", After:=ActiveCell, LookIn:= _
        xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
        xlNext, MatchCase:=False, SearchFormat:=False).Activate
    ActiveCell.Offset(-4).Resize(5).ClearContents
 
Upvote 0
While this works well, I need to delete the row with the word Global in and also the 4 rows above.

How would I do this?

Thanks
 
Upvote 0
Try:

Rich (BB code):
    Cells.Find(What:="Global", After:=ActiveCell, LookIn:= _
        xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
        xlNext, MatchCase:=False, SearchFormat:=False).Activate
    ActiveCell.Offset(-4).Resize(5).EntireRow.Delete
 
Upvote 0
Thanks very much again. That works perfectly.

I'm having trouble doing a general file reference as well.

After the piece of code you gave me need to insert:

ActiveSheet.Range("$A$1:$BV$3294").RemoveDuplicates Columns:=16, Header:= xlYes

But the range will always change. How would I select everything and remove duplicates based on the values in Col 16? I've tried a few things but nothing seems to work.

Thanks again for your time.
 
Upvote 0
Try:

Code:
Dim LastRow As Long
With ActiveSheet
    LastRow = .Range("A" & .Rows.Count).End(xlUp).Row
    .Range("A1:BV" & LastRow).RemoveDuplicates Columns:=16, Header:= xlYes
End With
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,849
Members
452,948
Latest member
UsmanAli786

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