Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 69
Default If Then to delete sheet if B1 blank

Excel 2003 SR2

I'm moving a large file into row range worksheets (5000 lines go into each
worksheet) which is then tested for blanks in Column B. If there are blanks
the row is deleted. Then I test to see if the worksheets past the 20000th
row are blank (B1 will always be blank if the whole worksheet is blank). If
true, delete the worksheet without displaying the warning.

My problem is the code (below) deletes the worksheet whether B1 is blank or
not ! I've cut and pasted other examples to get this formula and probably
did not cut enough or paste enough.

Any help would be appreciated!

CaroleO

If IsEmpty(Worksheets("20000").Range("B1")) Then
Application.DisplayAlerts = False
Sheets("20000").Delete
Application.DisplayAlerts = True
Else
Sheets("20000").Select
Columns("B:B").Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.EntireRow.Delete
End If
If IsEmpty(Worksheets("25000").Range("B1")) Then
Application.DisplayAlerts = False
Sheets("25000").Delete
Else
Sheets("25000").Select
Columns("B:B").Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.EntireRow.Delete
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default If Then to delete sheet if B1 blank

Is this code in a general module or is it in a worksheet module (maybe run by
clicking on a commandbutton from the Control toolbox toolbar?)

If it's in a general module, I don't see a problem (no testing, though).

If it's behind a worksheet, then any unqualified ranges will belong to the
worksheet that owns the code.

In any event, I'd use code like this to avoid the select's:

With Worksheets("20000")
If IsEmpty(.Range("B1").value) Then
Application.DisplayAlerts = False
.delete
Application.DisplayAlerts = True
Else
on error resume next 'just in case there are no blanks
.Columns("B:B").SpecialCells(xlCellTypeBlanks).Ent ireRow.Delete
on error goto 0
End If
End With

And I didn't see anything wrong with the isempty() portion. I don't have a
guess why you're seeing the worksheet get deleted.


Carole O wrote:

Excel 2003 SR2

I'm moving a large file into row range worksheets (5000 lines go into each
worksheet) which is then tested for blanks in Column B. If there are blanks
the row is deleted. Then I test to see if the worksheets past the 20000th
row are blank (B1 will always be blank if the whole worksheet is blank). If
true, delete the worksheet without displaying the warning.

My problem is the code (below) deletes the worksheet whether B1 is blank or
not ! I've cut and pasted other examples to get this formula and probably
did not cut enough or paste enough.

Any help would be appreciated!

CaroleO

If IsEmpty(Worksheets("20000").Range("B1")) Then
Application.DisplayAlerts = False
Sheets("20000").Delete
Application.DisplayAlerts = True
Else
Sheets("20000").Select
Columns("B:B").Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.EntireRow.Delete
End If
If IsEmpty(Worksheets("25000").Range("B1")) Then
Application.DisplayAlerts = False
Sheets("25000").Delete
Else
Sheets("25000").Select
Columns("B:B").Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.EntireRow.Delete


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default If Then to delete sheet if B1 blank

Try this on a copy

Sub Testing()
dim aWS as worksheet

application.displayalerts = false

'Deletes all worksheets that have B1 empty
for each aws in activeworkbook.worksheets
if isempty(aws.range("B1"))then
aws.delete
end if
next aws
application.displayalerts = true

End Sub

HTH,
Barb Reinhardt

"Carole O" wrote:

Excel 2003 SR2

I'm moving a large file into row range worksheets (5000 lines go into each
worksheet) which is then tested for blanks in Column B. If there are blanks
the row is deleted. Then I test to see if the worksheets past the 20000th
row are blank (B1 will always be blank if the whole worksheet is blank). If
true, delete the worksheet without displaying the warning.

My problem is the code (below) deletes the worksheet whether B1 is blank or
not ! I've cut and pasted other examples to get this formula and probably
did not cut enough or paste enough.

Any help would be appreciated!

CaroleO

If IsEmpty(Worksheets("20000").Range("B1")) Then
Application.DisplayAlerts = False
Sheets("20000").Delete
Application.DisplayAlerts = True
Else
Sheets("20000").Select
Columns("B:B").Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.EntireRow.Delete
End If
If IsEmpty(Worksheets("25000").Range("B1")) Then
Application.DisplayAlerts = False
Sheets("25000").Delete
Else
Sheets("25000").Select
Columns("B:B").Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.EntireRow.Delete

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
Delete blank sheet linglc Excel Programming 6 July 4th 06 01:51 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
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 02:52 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"