Application.ScreenUpdating = False
Sheets("Sheet2").Select
If WorksheetFunction.CountA(Cells) = 0 Then
MsgBox ("Sheet2 is blank.", vbOKOnly + vbInformation)
End If
End Sub
Sub CheckForBlankWS()
Application.ScreenUpdating = False
Dim wBook As Workbook
Dim wSheet As Worksheet
Set wBook = ActiveWorkbook
For Each wSheet In wBook.Worksheets
With wSheet
If WorksheetFunction.CountA(Cells) = 0 Then
MsgBox (wSheet.Name & " is blank.", vbOKOnly + vbInformation)
End If
End With
Next wSheet
End Sub
This is definitely the best way. Excel keeps track of the number of used cells as you go, so this solution does not require any calculation. It's just a simple lookup.. Very fast and accurate.I realize this is a very old post. However, I thought I may still be able to help someone looking to do this.
The easiest way I know to check for a blank sheet is by taking advantage of the CountA worksheet function.
To check a specific sheet
Code:Application.ScreenUpdating = False Sheets("Sheet2").Select If WorksheetFunction.CountA(Cells) = 0 Then MsgBox ("Sheet2 is blank.", vbOKOnly + vbInformation) End If End Sub
To loop through all sheets in a Workbook
Code:Sub CheckForBlankWS() Application.ScreenUpdating = False Dim wBook As Workbook Dim wSheet As Worksheet Set wBook = ActiveWorkbook For Each wSheet In wBook.Worksheets With wSheet If WorksheetFunction.CountA(Cells) = 0 Then MsgBox (wSheet.Name & " is blank.", vbOKOnly + vbInformation) End If End With Next wSheet End Sub
There's a minor flaw in this solution. Instead of using "s.Range("A1") = "" " use "isempty(sRange("A1")=true". If A1 contains non-text (e.g., a PictureInCell) you will get a runtime error. Using CountA, though is a better solution in my opinion.Hi,
Funny, the below line create an error in my swedish version of XL (bug or feature or language specific...)
If s.UsedRange.Address = "$A$1" And s.Range("A1") = "" Then
That´s why I used above solution with the With-statement
Nevertheless, glad it worked out for You
Kind regards,
Dennis