ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   check if worksheet is empty (https://www.excelbanter.com/excel-programming/342452-check-if-worksheet-empty.html)

Lynn[_7_]

check if worksheet is empty
 
Hi,
how can i check if worksheets labeled sheet2, sheet3 and sheet4 is
empty?
thanks


Ron de Bruin

check if worksheet is empty
 
One way

If Application.WorksheetFunction.CountA(sheets("Sheet 2").Cells) = 0 Then

If 0 there is no data on the sheet

Here is a working example to delete empty sheets

Sub Delete_EmptySheets()
Dim sh As Worksheet 'Ron de Bruin, programming, 2002-12-28
'On Error Resume Next 'possibility of all sheets blank
For Each sh In ThisWorkbook.Worksheets
If Application.WorksheetFunction.CountA(sh.Cells) = 0 Then
Application.DisplayAlerts = False
sh.Delete
Application.DisplayAlerts = True
End If
Next
'On Error goto 0 'Excel must have one sheet/workbook
End Sub



--
Regards Ron de Bruin
http://www.rondebruin.nl


"Lynn" wrote in message oups.com...
Hi,
how can i check if worksheets labeled sheet2, sheet3 and sheet4 is
empty?
thanks





All times are GMT +1. The time now is 03:50 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com