Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Delete blank sheet

How do I delete all blank sheets in a file using VBA? Thanks in advance for
any answers.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Delete blank sheet

Try this

Dim sh As Worksheet

Application.DisplayAlerts = False
For Each sh In ActiveWorkbook.Worksheets
If ActiveWorkbook.Worksheets.Count 1 Then
If IsEmpty(ActiveSheet.UsedRange) Then
sh.Delete
End If
End If
Next sh
Application.DisplayAlerts = True


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"linglc" wrote in message
...
How do I delete all blank sheets in a file using VBA? Thanks in advance

for
any answers.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Delete blank sheet

Hi Linglc,

Try:

'=============
Public Sub Tester()
Dim SH As Worksheet

On Error GoTo XIT
Application.DisplayAlerts = False
For Each SH In ActiveWorkbook.Worksheets
With SH
If Application.CountA(.Cells) = 0 Then
SH.Delete
End If
End With
Next SH

XIT:
Application.DisplayAlerts = True

End Sub
'<<=============


---
Regards,
Norman


"linglc" wrote in message
...
How do I delete all blank sheets in a file using VBA? Thanks in advance
for
any answers.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Delete blank sheet

careful you don't (try to) delete them all <vbg

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Norman Jones" wrote in message
...
Hi Linglc,

Try:

'=============
Public Sub Tester()
Dim SH As Worksheet

On Error GoTo XIT
Application.DisplayAlerts = False
For Each SH In ActiveWorkbook.Worksheets
With SH
If Application.CountA(.Cells) = 0 Then
SH.Delete
End If
End With
Next SH

XIT:
Application.DisplayAlerts = True

End Sub
'<<=============


---
Regards,
Norman


"linglc" wrote in message
...
How do I delete all blank sheets in a file using VBA? Thanks in advance
for
any answers.





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Delete blank sheet

Hi Bob,

careful you don't (try to) delete them all <vbg


Try my code on an emty workbook! <ebg


---
Regards,
Norman




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Delete blank sheet

Hi Bob,

Even an emPty one!


---
Regards,
Norman


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Delete blank sheet

Hi Norman,

I missed your error handler <vbg. I should have done it that way (doh!)

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Norman Jones" wrote in message
...
Hi Bob,

Even an emPty one!


---
Regards,
Norman




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
Need help Taking alot data from one sheet (if not blank) and copying toa list on another sheet. Alex Zuniga Excel Worksheet Functions 1 November 25th 09 11:54 PM
"BLANK" - need to delete anjgoss Excel Worksheet Functions 3 August 25th 05 05:31 PM
Delete blank row only if 2 consecutive blank rows Amy Excel Programming 2 October 21st 04 05:24 PM
Delete if blank... CPower[_31_] Excel Programming 3 August 11th 04 12:21 AM
Macro to look for blank rows in sheet, delete the row and autofit JDerm Excel Programming 1 May 13th 04 07:08 PM


All times are GMT +1. The time now is 03:16 PM.

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"