PDA

View Full Version : [SOLVED:] Delete a sheet IF sheetname doesnt contain the string 'rules'



crmpicco
05-12-2005, 07:23 AM
I'm looking for code that will Delete a sheet IF sheetname doesnt contain the string 'rules'.

thanks.

Picco

Bob Phillips
05-12-2005, 07:38 AM
I'm looking for code that will Delete a sheet IF sheetname doesnt contain the string 'rules'.

Assuming you mean the active worksheet


Sub DeleteSheet()
If Not ActiveSheet.Name Like "*rules*" Then
Application.DisplayAlerts = False
ActiveSheet.Delete
Application.DisplayAlerts = True
End If
End Sub

austenr
05-12-2005, 07:39 AM
Function ContainsText(Rng As Range, Text As String) As String
Dim T As String
Dim myCell As Range
For Each myCell In Rng 'look in each cell
If InStr(myCell.Text, Text) > 0 Then 'look in the string for the text
If Len(T) = 0 Then ' look in the string for the text
T = myCell.Address(False, False)
Else
T = T & "," & myCell.Address(False, False)
End If
End If
Next myCell
ContainsText = T
End Function

HTH

Norie
05-12-2005, 08:09 AM
How about this?


Sub DeleteWS()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
If InStr("RULES", UCase(ws.Name)) Then
Application.DisplayAlerts = False
ws.Delete
Application.DisplayAlerts = True
End If
Next
End Sub