View Single Post
  #2   Report Post  
Jason Clement
 
Posts: n/a
Default not delete worksheets from names in a range

You can create a subroutine in vba like this:

Sub delete()
'Tell Excel to not prompt the deletion confirmation
Application.DisplayAlerts = False

For Each sh In ThisWorkbook.Sheets
forDeletion = True

' Sheet1.Range("A1:A3") refers to the range of cells that
' hold the sheet needs we don't want to delete. You're better
' off using a named range to refer to those.
For Each n In Sheet1.Range("A1:A3")
If sh.Name = n.Value Then
forDeletion = False
Exit For
End If
Next n
If forDeletion Then
sh.delete
End If
Next sh
End Sub




"DARREN FONG" wrote:

Is there anyway to delete worksheets where one worksheet contains a
range with the names of worksheets I DONT want to delete?
i.e I want to have a code that says "do not delete worksheets in the range
but delete all other worksheets"