Excel Macro to find the next number 1 in Column A:A

SteveD 725 Reputation points
2026-10-26T19:37:59.4433333+00:00

Hello from Steve

A Macro In Excel Objective please is to find the next number 1 in Column A:A

Once found delete all above the number 1 to Column A:1

Thank you

Microsoft 365 and Office | Excel | For home | Windows
0 comments No comments

Answer accepted by question author
Marcin Policht 113.3K Reputation points MVP Volunteer Moderator
2026-10-26T21:35:25.72+00:00

The following macro searches Column A for the first cell containing the number 1. Once found, it deletes all rows above that cell, so the row containing 1 becomes the new Row 1.

Sub DeleteRowsAboveFirstOne()

    Dim ws As Worksheet
    Dim foundCell As Range

    Set ws = ActiveSheet

    Set foundCell = ws.Columns("A").Find( _
        What:=1, _
        After:=ws.Cells(ws.Rows.Count, "A"), _
        LookIn:=xlValues, _
        LookAt:=xlWhole, _
        SearchOrder:=xlByRows, _
        SearchDirection:=xlNext, _
        MatchCase:=False)

    If Not foundCell Is Nothing Then
        If foundCell.Row > 1 Then
            ws.Rows("1:" & foundCell.Row - 1).Delete
        End If
    Else
        MsgBox "The number 1 was not found in Column A.", vbInformation
    End If

End Sub

To run the macro, press Alt + F11 in Excel, select Insert > Module, paste the code into the module, and run DeleteRowsAboveFirstOne.

Note that the macro searches for a cell containing the exact numeric value 1, not a number such as 10 or 21. It deletes entire worksheet rows above the first match, preserving the row containing 1 and all rows below it.


If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.

hth

Marcin

Was this answer helpful?

1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.