Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting sheets not working 2

Status
Not open for further replies.

willydude

Programmer
Oct 24, 2006
123
US
This is the kind of problem that drives me crazy. The following works. It deletes all sheets that have the name sheet.
Code:
Sub DeleteWorksheets()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim sheet As Worksheet
For Each sheet In ActiveWorkbook.Worksheets
    If InStr(1, LCase(sheet.Name), "sheet") Then
        sheet.Delete
    End If
Next sheet
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
The following should delete all sheets EXCEPT the ones named "OriginalData" and "SalesPeople".
Code:
Sub CleanCommissionsBySalesBreakDown()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim sheet As Worksheet
'On Error Resume Next
For Each sheet In ActiveWorkbook.Worksheets
    If Not InStr(1, LCase(sheet.Name), "OriginalData") Or
Not InStr(1, LCase(sheet.Name), "SalesPeople") Then
    sheet.Delete
    End If
Next sheet
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
The above proc deletes "OriginalData" and
"SalesPeople".

I'm sure that it's simple, but....
 
Both of the following want to delete the "OriginalData" and "SalesPeople" sheets. But they should not.

Code:
If Not (InStr(LCase(sheet.Name), "originaldata")) + _
    Not (InStr(LCase(sheet.Name), "salespeople")) = 0 Then
       sheet.Delete
Code:
If Not InStr(LCase(sheet.Name), "originaldata") + _
    Not InStr(LCase(sheet.Name), "salespeople") = 0 Then
        sheet.Delete

Thanks for the help. I'll see if I can't do it some other way.
 
WinBlowsMe has it. It was in the parenthesis set up.

Thanks to everyone for their help and patience.

Bill
 
It was in the parenthesis set up
You already had this answer 17 Jan 07 18:03
 
The negation of
A Or B
is either
Not A And Not b
or
Not (A Or B)"

You're right. I just didn't see it.

Sorry and thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top