Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Testing for empty sheet

What's the easiest method to test for an empty worksheet?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,365
Default Testing for empty sheet

Define 'empty'.

Some might consider the result of a formula as =A1 + B1 with a result of
zero as "empty", but of course it isn't.

Here's one test I came up with, someone else may come up with a better one:

If Activesheet.UsedRange.Cells.Count = 1 And _
IsEmpty(Range(ActiveSheet.UsedRange.Address)) Then
MsgBox "Empty Sheet"
Exit Sub
End If

to make doubly sure, you could put this right after the above

If Application.WorksheetFunction.CountBlank(ActiveShe et.UsedRange) = _
ActiveSheet.UsedRange.Cells.Count Then
MsgBox "Sheet is effectively empty."
End If

To explain the first one: on a brand new sheet UsedRange will return a cells
count of 1 even though you've never put anything in it, and by testing that
one cell's contents you can confirm whether or not it is truly an empty
sheet. But the results of a math formula of any type are going to make it
appear not-empty.

Hope this helps.

"Stu W" wrote:

What's the easiest method to test for an empty worksheet?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Testing for empty sheet

Application.CountA(Activesheet.cells) should equal 0.

--
Regards,
Tom Ogilvy


"Stu W" wrote:

What's the easiest method to test for an empty worksheet?

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
empty cells - best way of testing for them Chris Strug Excel Programming 3 August 10th 04 11:53 AM
Testing for null or empty gwgeller[_3_] Excel Programming 4 January 29th 04 08:34 PM
testing if a sheet is protected John Wilson Excel Programming 0 September 9th 03 07:21 PM
Testing to see if a sheet name exists anita Excel Programming 1 September 4th 03 10:14 PM
testing for non-empty cells Paul James[_2_] Excel Programming 6 August 3rd 03 09:04 AM


All times are GMT +1. The time now is 01:24 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"