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

  • Home
  • SEARCH
  • 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 8406023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:59:07+00:00 2026-06-09T22:59:07+00:00

This script works, but only if I run it twice. Anyone have an idea

  • 0

This script “works”, but only if I run it twice. Anyone have an idea of why this is happening? Dealing with the special types has been somewhat of a nightmare, I’m not sure if that’s just me or known issues. Using Excel 2010 on Windows 7. I’ve tried repeating the code twice as well to no avail. I tried putting this in a Do Until and ALWAYS get stuck in a forever loop the first time I execute. I’m not sure why executing it the second time seems to work

'Remove all Blank Cells

    On Error Resume Next
    For i = Cells.SpecialCells(xlCellTypeBlanks).Count To 1 Step -1
    Cells.SpecialCells(xlCellTypeBlanks).EntireRow.Delete
    Next i

  If Cells.SpecialCells(xlCellTypeBlanks).Count = 0 Then 
     ActiveWorkbook.Close (True)
  • 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-06-09T22:59:09+00:00Added an answer on June 9, 2026 at 10:59 pm

    EDIT: Updated answer to show how deleting a “specialcells” range doesn’t reset the sheet’s UsedRange property, and how that can lead to problems.

    Try running this sub multiple times on a sheet with or without the call to Activesheet.UsedRange commented out…

    Sub Tester()
        Dim rng As Range
    
        On Error Resume Next
        Set rng = ActiveSheet.Cells.SpecialCells(xlCellTypeBlanks)
        On Error GoTo 0
    
        If Not rng Is Nothing Then
            Debug.Print "have empty cells"
            rng.EntireRow.Delete
            ActiveSheet.UsedRange
        Else
            Debug.Print "no empty cells"
        End If
    
    End Sub
    

    Saving and re-opening seems to also reset UsedRange…

    EDIT2 you should be very careful using this! It deletes whole rows even if there are non-blank cells in that row. It will be OK for certain types of data layout, but not for others. Under certain circumstances you may also see an error “Cannot use that command on overlapping selection” when calling “delete”.

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

Sidebar

Related Questions

I have this script that works, but I need to change the format of
This script works fine on single click but on double click it shows both
I just finished this script it works well, but I am struggling to pass
I am using a script from this discussion: https://wordpress.stackexchange.com/a/14711/14649 It works great, but when
Why doesn't this work <script src=jquery.js/> But this works <script src=jquery.js></script> ? Firefox 3.5.8
Can anyone tell me why this bash script works if I cut and paste
I am trying to batch rename old log files, but the script only works
I have a script that works fine when I run it manually in R
I have a python script that works great when run by itself. Based on
I swear this script worked fine last night but can't get it to work

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.