Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Delete worksheet if cell is empty

Hello,
I have figured out how to delete a sheet if a cell contains no data
(although it does not seem to work consistently), but I cannot figure out how
to stop the next section of code if the sheet is deleted. The code for the
deleted sheet (if it had contained data) gets applied to the next worksheet.

Here is what I have for the deletion...should this be followed by "else" or
something? I am tyring to say "if cell A12 has no data, delete the worksheet"

If IsEmpty(Range("A12")) Then SelectedSheets.Delete

Thanks!
Kathy
--
RU0824V
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Delete worksheet if cell is empty

I have ten sheets that my macro runs through...if there is no report data on
a sheet, I want it to delete the sheet. The the cell to check for data is not
going to be A12 on all sheets.

--
RU0824V


"Don Guillett" wrote:

Are you trying to delete ONE sheet or any sheet in the workbook where cell
a12 is empty?

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"RU0824V" wrote in message
...
Hello,
I have figured out how to delete a sheet if a cell contains no data
(although it does not seem to work consistently), but I cannot figure out
how
to stop the next section of code if the sheet is deleted. The code for the
deleted sheet (if it had contained data) gets applied to the next
worksheet.

Here is what I have for the deletion...should this be followed by "else"
or
something? I am tyring to say "if cell A12 has no data, delete the
worksheet"

If IsEmpty(Range("A12")) Then SelectedSheets.Delete

Thanks!
Kathy
--
RU0824V



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Delete worksheet if cell is empty

Sub deletesheetifcellSempty()
Application.DisplayAlerts = False
For Each sh In ActiveWorkbook.Worksheets

'if a12
'If Len(Application.Trim(sh.Range("a12"))) < 1 Then sh.Delete

'following line is ONE line for NO cell with ANYTHING, including header row
If Len(Application.Trim(sh.Cells.SpecialCells(xlCellT ypeLastCell))) < 1 Then
sh.Delete

Next sh
Application.DisplayAlerts = True
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"RU0824V" wrote in message
...
I have ten sheets that my macro runs through...if there is no report data
on
a sheet, I want it to delete the sheet. The the cell to check for data is
not
going to be A12 on all sheets.

--
RU0824V


"Don Guillett" wrote:

Are you trying to delete ONE sheet or any sheet in the workbook where
cell
a12 is empty?

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"RU0824V" wrote in message
...
Hello,
I have figured out how to delete a sheet if a cell contains no data
(although it does not seem to work consistently), but I cannot figure
out
how
to stop the next section of code if the sheet is deleted. The code for
the
deleted sheet (if it had contained data) gets applied to the next
worksheet.

Here is what I have for the deletion...should this be followed by
"else"
or
something? I am tyring to say "if cell A12 has no data, delete the
worksheet"

If IsEmpty(Range("A12")) Then SelectedSheets.Delete

Thanks!
Kathy
--
RU0824V




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 to delete empty pages in my worksheet Bailey Excel Discussion (Misc queries) 1 February 9th 08 05:36 PM
how do i find and delete all empty rows in an excel worksheet AinSF Excel Worksheet Functions 3 September 1st 06 01:38 AM
How do I delete an empty worksheet. Jimmy Excel Worksheet Functions 10 February 3rd 05 05:43 PM
How to delete empty rows in a worksheet Bob Reynolds[_3_] Excel Programming 0 June 24th 04 11:04 PM
Delete empty rows in a worksheet Scott Excel Programming 3 January 8th 04 10:09 PM


All times are GMT +1. The time now is 09:14 AM.

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"