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


Hi all. I've got a VB program that is eporting SQL data to a workbook.
It loops to create a new sheet for every employee. It's working well...
but I still have some format issues to overcome. I'm ok with VB, but
the Excel syntax is all new to me as of this project.

As my code creates a new sheet first before checking for the next
employee, it finishes by adding a new sheet to the very end of the
workbook. I tried using: *ActiveWindow.SelectedSheets.Delete*

Unfortunately, the program is jumping back to the first sheet before
deleting. This doesn't work well anyway, because finishes the code out
by prompting the user is s/he wants to delete before deleting.

Is there a way to search the active workbook and delete any sheets than
contain no data?

Thx!


--
wolfdogg
------------------------------------------------------------------------
wolfdogg's Profile: http://www.excelforum.com/member.php...o&userid=25269
View this thread: http://www.excelforum.com/showthread...hreadid=387569

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Deleting a blank sheet in a workbook

Hi,

you can make a loop on all worksheets and use the CountA function

with Application
.DisplayAlerts = False
For Each sh In ActiveWorkbook.Worksheets
If .WorksheetFunction.CountA(sh.Cells) = 0 Then sh.Delete
Next
..DisplayAlerts = False
End with

Be sure that at least one of the sheets contains data, for otherwise VBA
will return an error message , cos Excel can't afford the workbook to
have no sheets at all.

Regards

wolfdogg a écrit :
Hi all. I've got a VB program that is eporting SQL data to a workbook.
It loops to create a new sheet for every employee. It's working well...
but I still have some format issues to overcome. I'm ok with VB, but
the Excel syntax is all new to me as of this project.

As my code creates a new sheet first before checking for the next
employee, it finishes by adding a new sheet to the very end of the
workbook. I tried using: *ActiveWindow.SelectedSheets.Delete*

Unfortunately, the program is jumping back to the first sheet before
deleting. This doesn't work well anyway, because finishes the code out
by prompting the user is s/he wants to delete before deleting.

Is there a way to search the active workbook and delete any sheets than
contain no data?

Thx!


  #3   Report Post  
Posted to microsoft.public.excel.programming
Roy Roy is offline
external usenet poster
 
Posts: 53
Default Deleting a blank sheet in a workbook

Wolfdogg,

Couldn't you alter your loop to create the new sheet after verifying it is
actually needed. It would look better from an asthetic standpoint to not add
an uneeded sheet and then delete it later. It sounds like a "simple"
re-arrangement of exisiting code to me.

Roy

"wolfdogg" wrote:


Hi all. I've got a VB program that is eporting SQL data to a workbook.
It loops to create a new sheet for every employee. It's working well...
but I still have some format issues to overcome. I'm ok with VB, but
the Excel syntax is all new to me as of this project.

As my code creates a new sheet first before checking for the next
employee, it finishes by adding a new sheet to the very end of the
workbook. I tried using: *ActiveWindow.SelectedSheets.Delete*

Unfortunately, the program is jumping back to the first sheet before
deleting. This doesn't work well anyway, because finishes the code out
by prompting the user is s/he wants to delete before deleting.

Is there a way to search the active workbook and delete any sheets than
contain no data?

Thx!


--
wolfdogg
------------------------------------------------------------------------
wolfdogg's Profile: http://www.excelforum.com/member.php...o&userid=25269
View this thread: http://www.excelforum.com/showthread...hreadid=387569


  #4   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default Deleting a blank sheet in a workbook

I think you meant to turn alerts back on the end <g

..DisplayAlerts = True
End with



"anonymousA" wrote:

Hi,

you can make a loop on all worksheets and use the CountA function

with Application
.DisplayAlerts = False
For Each sh In ActiveWorkbook.Worksheets
If .WorksheetFunction.CountA(sh.Cells) = 0 Then sh.Delete
Next
..DisplayAlerts = False
End with

Be sure that at least one of the sheets contains data, for otherwise VBA
will return an error message , cos Excel can't afford the workbook to
have no sheets at all.

Regards

wolfdogg a écrit :
Hi all. I've got a VB program that is eporting SQL data to a workbook.
It loops to create a new sheet for every employee. It's working well...
but I still have some format issues to overcome. I'm ok with VB, but
the Excel syntax is all new to me as of this project.

As my code creates a new sheet first before checking for the next
employee, it finishes by adding a new sheet to the very end of the
workbook. I tried using: *ActiveWindow.SelectedSheets.Delete*

Unfortunately, the program is jumping back to the first sheet before
deleting. This doesn't work well anyway, because finishes the code out
by prompting the user is s/he wants to delete before deleting.

Is there a way to search the active workbook and delete any sheets than
contain no data?

Thx!



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
deleting the blank rows from the sheet manu Excel Worksheet Functions 4 July 9th 07 09:29 PM
Deleting all but one blank row RealGomer Excel Discussion (Misc queries) 2 February 16th 06 06:55 PM
Deleting Blank Rows Nigel Bennett Excel Programming 1 March 16th 05 12:31 AM
Deleting Blank Rows LC[_5_] Excel Programming 1 June 3rd 04 06:55 PM
Deleting every sheet in workbook after Worksheets(4) Todd Huttenstine[_3_] Excel Programming 2 January 2nd 04 06:50 AM


All times are GMT +1. The time now is 11:10 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"