Detect for empty excel sheet

  • Thread starter Thread starter lkfstephen
  • Start date Start date
L

lkfstephen

I need to detect a empty excel sheet by VBA.

I know that CountA(Activesheet) = 0 and Activesheet.Shapes.Count = 0 is
Useful. But I found that it is not sufficient. For example, if I just
change the background color and the border of Cell A1. The code will
return true even the Activesheet is not empty at all.

I also tried about the code for Activesheet.UsedRange. But I found that
if the sheet is empty, it will always return A1:A1. But again, it is
not sufficient. At least it cannot pass the above test case.

Could any one tell me how to test a excel sheet is empty or not in all
cases? I think it is possible, because some Excel Add-Ins can do that.

Thank you very much.

Stephen Lai
 
Dear Michael,

Thank you for your nice answer.

But what I want is that "The function return true if and only if the
sheet is empty".
What I mean by empty is if I print the sheet, it will has something to
print.

Therefore, if the sheet is just changed cell A1's border or A1's
background color, it should also return false. Because the sheet is not
empty at all.

Again, thank you for your answer.

Stephen Lai


Michael ¼g¹D¡G
 
Stephen,
May be get the number of pages that would be printed. If 0 return True:
Worksheets(3).Select
MsgBox ExecuteExcel4Macro("Get.Document(50)")

NickHK

Dear Michael,

Thank you for your nice answer.

But what I want is that "The function return true if and only if the
sheet is empty".
What I mean by empty is if I print the sheet, it will has something to
print.

Therefore, if the sheet is just changed cell A1's border or A1's
background color, it should also return false. Because the sheet is not
empty at all.

Again, thank you for your answer.

Stephen Lai


Michael ¼g¹D¡G
 
Dear NickHK,

Thank you very much. It works. ^^"

Stephen Lai

NickHK 寫é“:
 
This will not detect any named ranges, conditional formatting, data
validation etc, so depends what you mean by "empty sheet".

NickHK

Dear NickHK,

Thank you very much. It works. ^^"

Stephen Lai

NickHK ??:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top