• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How can I delete every empty row of an Excel document?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How can I delete every empty row of an Excel document?


  • Subject: Re: How can I delete every empty row of an Excel document?
  • From: Stan Cleveland <email@hidden>
  • Date: Wed, 26 Feb 2014 13:03:28 -0800

Hi Bert,

I've been following this thread, but have been rather busy. I finally got some time to see if I could find an efficient, non-looping method. It seems that formula array is the "magic command" that Paul wondered about.

tell application "Microsoft Excel"
set usedAreas to rows of used range of active sheet whose formula array is ""
if usedAreas is not missing value then delete range (reverse of usedAreas)
end tell

Reversing the usedAreas list is necessary, because Excel deletes rows in the order listed. If not reversed, after one row is deleted, Excel recognizes that the other rows have shifted and will abort with only the first empty row deleted.

Also, if there are no empty rows, then usedAreas is defined as missing value, which must be tested for.

There's another issue. Using this method, all empty rows before the first non-empty row are NOT considered part of the used range and won't be deleted. If you'd like those gone as well, then add the following two lines of code inside the bottom of the tell block.

set firstRow to first row index of used range of active sheet
if firstRow > 1 then delete range range ("1:" & (firstRow - 1))

One last observation. In this case, the delete range commands don't need the shift shift up parameter, since entire rows are being deleted and shifting up is implicit.

BTW, this was tested with Excel 2011 (14.3.9) and Excel 2008 (12.3.6).

HTH,
Stan C.

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: How can I delete every empty row of an Excel document?
      • From: Thomas Fischer <email@hidden>
References: 
 >How can I delete every empty row of an Excel document? (From: Bert Groeneveld <email@hidden>)
 >Re: How can I delete every empty row of an Excel document? (From: Thomas Fischer <email@hidden>)
 >Re: How can I delete every empty row of an Excel document? (From: Thomas Fischer <email@hidden>)
 >Re: How can I delete every empty row of an Excel document? (From: "koenig.yvan" <email@hidden>)
 >Re: How can I delete every empty row of an Excel document? (From: Thomas Fischer <email@hidden>)

  • Prev by Date: Re: problem with "Contacts"
  • Next by Date: Re: problem with "Contacts"
  • Previous by thread: Re: How can I delete every empty row of an Excel document?
  • Next by thread: Re: How can I delete every empty row of an Excel document?
  • Index(es):
    • Date
    • Thread