A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

not delete worksheets from names in a range



 
 
Thread Tools Display Modes
  #1  
Old November 10th, 2005, 10:35 PM
DARREN FONG
external usenet poster
 
Posts: n/a
Default not delete worksheets from names in a range

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"
  #2  
Old November 10th, 2005, 11:04 PM
Jason Clement
external usenet poster
 
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"

  #3  
Old November 10th, 2005, 11:07 PM
Rowan Drummond
external usenet poster
 
Posts: n/a
Default not delete worksheets from names in a range

One way:

Sub DelShts()
Dim rng() As Variant
Dim i As Integer
Dim ans As Variant
Application.DisplayAlerts = False
rng = Range("A2:A6")
For i = Sheets.Count To 1 Step -1
On Error Resume Next
ans = Application.WorksheetFunction. _
Match(Sheets(i).Name, rng, 0)
If ans = Empty Then Sheets(i).Delete
ans = Empty
On Error GoTo 0
Next i
Application.DisplayAlerts = True
End Sub

Hope this helps
Rowan

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"

  #4  
Old November 11th, 2005, 05:31 PM
DARREN FONG via OfficeKB.com
external usenet poster
 
Posts: n/a
Default not delete worksheets from names in a range

Jason,

Thanks for your help, however it does'nt seem to work

I think this is because "n" is not defined, I've tried a few things but
nothing works as yet

Cheers

Daz

Jason Clement wrote:
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

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"


--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...excel/200511/1
 




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
deleting worksheets from names in a range Jenn General Discussion 2 August 23rd, 2005 12:00 AM
copying cell names Al General Discussion 3 August 11th, 2005 03:01 PM
Range Names Wes Worksheet Functions 2 June 27th, 2005 11:36 PM
Range across worksheets reab Worksheet Functions 1 November 26th, 2003 09:30 PM


All times are GMT +1. The time now is 01:43 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.