Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6471971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:17:13+00:00 2026-05-25T06:17:13+00:00

I have the following VBA code within excel. It’s goal is to remove a

  • 0

I have the following VBA code within excel. It’s goal is to remove a row if the given text is found, as well as remove the row directly below it. It needs to scan roughly 700k rows and is taking roughly an hour to do 100k rows. Does anyone see any optimization?

Sub RemovePageHeaders()
    Application.ScreenUpdating = False
    Dim objRange As Range
    Set objRange = Cells.Find("HeaderText")
    While objRange <> ""
        objRange.Offset(1, 0).Rows(1).EntireRow.Delete
        objRange.Rows(1).EntireRow.Delete
        Set objRange = Cells.Find("HeaderText")
    Wend
    MsgBox ("I'm done removing page headers!")
End Sub

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T06:17:14+00:00Added an answer on May 25, 2026 at 6:17 am

    Try the following sub. It loops from the bottomm-most row to the top, checking column 3 for “HeaderText”. If that’s found, it delete the row and the one below it. On a C2D E8500 with 2 gigs of RAM it takes just over a minute per 100,000 rows on a sheet with 1 million rows.

    Sub RemoveHeaders()
        Dim i As Long
    
        Application.ScreenUpdating = False
        Debug.Print "Started: " & Now
        For i = ActiveSheet.UsedRange.Rows.Count To 1 Step -1
            If ActiveSheet.Cells(i, 3) = "HeaderText" Then
                ActiveSheet.Range(i & ":" & i + 1).EntireRow.Delete
            End If
        Next i
        Application.ScreenUpdating = True
        Debug.Print "Finished: " & Now
    End Sub
    

    EDIT
    For a slightly ghetto but possibly much faster solution try this:

    1. Change the constant in the below code to the number of the first column that’s blank in every row. For example if your data takes up columns A-F, you want the constant to be 7 (column G).
    2. Run the code, it will put the row number next to every entry. Should take around 30 seconds.
    3. Sort the ENTIRE data by column C; this should take less than a minute.
    4. Find “HeaderText” visually, select and delete all the rows.
    5. Sort by your row-numbered column (“G” in my example).
    6. Delete the row-numbered column (again, “G” in my example).

      Sub NumberColumns()
          Const BLANK_COLUMN = 7
          Dim i As Long
      
          For i = ActiveSheet.UsedRange.Rows.Count To 1 Step -1
              ActiveSheet.Cells(i, BLANK_COLUMN) = i
          Next i
          Debug.Print "done"
      

      End Sub

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Win-XP / Excel 2003 / VBA .... I have the following piece of code
I have the following VBA code inside an Excel macro: With ActiveSheet.QueryTables.Add( _ Connection:=ConnStr,
In Excel 2007 I have the following very simple code in VBA: Public Type
I have the following code in VBA (which resides in an Excel 2007 Workbook):
I have the following in a piece of VBA code: For i = 1
I have the following code for handling userforms on my spreadsheet VBA macros: Option
I have the following INSTR condition in Excel VBA which doesn't work (all the
I have the following vba-code in an MS-Access97-frontend which opens a word-document stored on
I have the following vba code to find occurrences of 0 in a following
We currently have an Excel spreadsheet containing a large amount of VBA code. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.