Hi Ashthaps,
Here's one solution:
Function IsWorksheetEmpty(ByVal strWorksheet As String) As Boolean
On Error Resume Next
Dim rng As Range
' Are there any cells with constants (non formulae)
Set rng =
Worksheets(strWorksheet).Cells.SpecialCells(xlCellTypeConstants, 23)
' If the rng variable is not empty - cells were found, so exit
If Not rng Is Nothing Then
GoTo ExitFunction
End If
' Are there any cells with formulae
Set rng =
Worksheets(strWorksheet).Cells.SpecialCells(xlCellTypeFormulas, 23)
' If the rng variable is not empty - cells were found, so exit
If Not rng Is Nothing Then
GoTo ExitFunction
End If
' no cells formula or constant cells were referenced so sheet empty
IsWorksheetEmpty = True
ExitFunction:
Exit Function
End Function
You can test the function like this:
Sub Test_IsWorksheetEmpty()
MsgBox IsWorksheetEmpty("Sheet1")
End Sub
However, I'm sure there must be a cleaner way. Maybe some-one else can come
up with a more graceful solution.
Marcus from Melbourne