PC Review


Reply
Thread Tools Rate Thread

Delete worksheet if cell is empty

 
 
RU0824V
Guest
Posts: n/a
 
      23rd Jun 2008
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 With Quote
 
 
 
 
Don Guillett
Guest
Posts: n/a
 
      23rd Jun 2008
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
(E-Mail Removed)
"RU0824V" <(E-Mail Removed)> wrote in message
news:4780DC8F-36A1-452F-B5DC-(E-Mail Removed)...
> 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 With Quote
 
RU0824V
Guest
Posts: n/a
 
      23rd Jun 2008
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
> (E-Mail Removed)
> "RU0824V" <(E-Mail Removed)> wrote in message
> news:4780DC8F-36A1-452F-B5DC-(E-Mail Removed)...
> > 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 With Quote
 
Don Guillett
Guest
Posts: n/a
 
      23rd Jun 2008
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(xlCellTypeLastCell))) < 1 Then
sh.Delete

Next sh
Application.DisplayAlerts = True
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"RU0824V" <(E-Mail Removed)> wrote in message
news:0FA3AF3C-B1B0-4ED6-BC4F-(E-Mail Removed)...
>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
>> (E-Mail Removed)
>> "RU0824V" <(E-Mail Removed)> wrote in message
>> news:4780DC8F-36A1-452F-B5DC-(E-Mail Removed)...
>> > 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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
need to delete empty pages in my worksheet Bailey Microsoft Excel Misc 1 9th Feb 2008 05:36 PM
how do i find and delete all empty rows in an excel worksheet =?Utf-8?B?QWluU0Y=?= Microsoft Excel Worksheet Functions 3 1st Sep 2006 01:38 AM
How do I delete an empty worksheet. =?Utf-8?B?SmltbXk=?= Microsoft Excel Worksheet Functions 10 3rd Feb 2005 05:43 PM
How to delete empty rows in a worksheet Bob Reynolds Microsoft Excel Programming 0 24th Jun 2004 11:04 PM
Delete empty rows in a worksheet Scott Microsoft Excel Programming 3 8th Jan 2004 10:09 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:15 PM.