Find specific text in column and delete all rows above

bradyj7

Board Regular
Joined
Mar 2, 2011
Messages
106
Hi all,

I'm trying to write a macro to find the text "Journey Start Event" in column e and delete all rows above this. There will only be one instance of this text. I've adapted the macro below from another one that detects the first instance of a text and deletes all rows above. However I cannot seem to get it to work and there are no errors. Any ideas?

Here is where I got the original code http://excel.bigresource.com/Track/excel-XkKkmdSJ/

Code:
Sub Deleterowsabove()
Dim foundOne As Range
On Error Resume Next
With ActiveSheet
    Set foundOne = .Range("E:E").Find(What:="Journey Start Event", After:=.Range("e1"), LookIn:=xlFormulas, _
                                LookAt:=xlPart, SearchOrder:=xlByRows, _
                                SearchDirection:=xlNext, MatchCase:=False)
    If foundOne.Row = 1 Then
        Range(.Range("e1"), foundOne.Offset(-1, 0)).EntireRow.Delete shift:=xlUp
    Else
    
End If
End With
On Error GoTo 0
End Sub
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Hi that works thanks.

I don't really understand why it should be > 1 if that text only appears once. But at least it works.

Would you know how to modify it to not delete row 1 as this rows has headings that I want to keep.

Thank you
 
Upvote 0
Try

Code:
    If foundOne.Row > 2 Then
        Range(.Range("e2"), foundOne.Offset(-1, 0)).EntireRow.Delete shift:=xlUp
    End If
 
Upvote 0
This left row 1 intact for me

Code:
Sub Deleterowsabove()
Dim foundOne As Range
On Error Resume Next
With ActiveSheet
    Set foundOne = .Range("E:E").Find(What:="Journey Start Event", After:=.Range("e1"), LookIn:=xlFormulas, _
                                LookAt:=xlPart, SearchOrder:=xlByRows, _
                                SearchDirection:=xlNext, MatchCase:=False)
    If foundOne.Row > 2 Then
        Range(.Range("e2"), foundOne.Offset(-1, 0)).EntireRow.Delete shift:=xlUp
    End If
End With
On Error GoTo 0
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,853
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