Link to home
Start Free TrialLog in
Avatar of Seamus2626
Seamus2626Flag for Ireland

asked on

Loop+delete code

Hi,

I need a sub that will loop through Col A until it finds the words "Dividend Breaks"

Once it finds this, go one cell up and delete all the rows back up to the top

E.G. if "Dividend Breaks was on A327, the code would select A326 and delete to the top (A1)

Thanks
Seamus
ASKER CERTIFIED SOLUTION
Avatar of StephenJR
StephenJR
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Seamus2626

ASKER

Magic!!

Thanks Stephen

Seamus
here it is
Sub delUp()
    Dim c1, c2
    Dim r As Range
    
    Set c1 = Cells(1, 1)
    Set c2 = c1.End(xlDown)
    Set r = Range(c1, c2)
    
    For Each c In r
      If InStr(c.Value, "Dividend Breaks") > 0 Then
        Range(c, c1).Select
        Selection.Delete Shift:=xlUp
        Exit For
      End If
    Next
End Sub

Open in new window

Thank you too HainKurt,

Cheers,
Seamus