Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Delete Sheets Problem

Hi

Why isnt this code working? It is coming up with the 'Type Mismatch' error.

Thanks

Sub DeleteSheets()

For x = 1 To Worksheets.Count
If Worksheets(x).Name < "Menu" Or "Sage Export" Then
Worksheets(x).Delete
End If
Next x

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 75
Default Delete Sheets Problem

Hi Edgar,

Try this. It worked for me.

Sub DeleteSheets()

For x = 1 To Worksheets.Count
If Worksheets(x).Name < "Menu" Or Worksheets(x).Name < "Sage Export"
Then
Worksheets(x).Delete
End If
Next x

End Sub

"Edgar Thoemmes" wrote:

Hi

Why isnt this code working? It is coming up with the 'Type Mismatch' error.

Thanks

Sub DeleteSheets()

For x = 1 To Worksheets.Count
If Worksheets(x).Name < "Menu" Or "Sage Export" Then
Worksheets(x).Delete
End If
Next x

End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Delete Sheets Problem

Edgar,

Another approach

Sub Macro1()
DeleteSheet "Menu"
DeleteSheet "Sage Export"
End Sub

'-----------------------------------------------------------------
Function DeleteSheet(Sh As String, _
Optional wb As Workbook) As Boolean
'-----------------------------------------------------------------
Dim oWs As Object
If wb Is Nothing Then Set wb = ActiveWorkbook
On Error Resume Next
Application.DisplayAlerts = False
wb.Sheets(Sh).Delete
Application.DisplayAlerts = True
On Error GoTo 0
End Function

--

HTH

RP

"Francis Ang" wrote in message
...
Hi Edgar,

Try this. It worked for me.

Sub DeleteSheets()

For x = 1 To Worksheets.Count
If Worksheets(x).Name < "Menu" Or Worksheets(x).Name < "Sage Export"
Then
Worksheets(x).Delete
End If
Next x

End Sub

"Edgar Thoemmes" wrote:

Hi

Why isnt this code working? It is coming up with the 'Type Mismatch'

error.

Thanks

Sub DeleteSheets()

For x = 1 To Worksheets.Count
If Worksheets(x).Name < "Menu" Or "Sage Export" Then
Worksheets(x).Delete
End If
Next x

End Sub



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Delete Sheets Problem

Seems like every sheet would meet that test. Sage Export < Menu or Menu
< Sage Export. I think you would need (besides the problem of the number
of sheets changing as each is deleted).

Sub DeleteSheets()
Dim j as Long, x as Long
j = 1
For x = 1 To Worksheets.Count
If Worksheets(j).Name < "Menu" And _
Worksheets(j).Name < "Sage Export" Then
Application.DisplayAlerts = False
Worksheets(j).Delete
Application.DisplayAlerts = True
Else
j = j + 1
End If
Next x
End Sub

to exclude Menu and Sage Export.

I actually ran this and it really did work for me.

--
Regards,
Tom Ogilvy


"Francis Ang" wrote in message
...
Hi Edgar,

Try this. It worked for me.

Sub DeleteSheets()

For x = 1 To Worksheets.Count
If Worksheets(x).Name < "Menu" Or Worksheets(x).Name < "Sage Export"
Then
Worksheets(x).Delete
End If
Next x

End Sub

"Edgar Thoemmes" wrote:

Hi

Why isnt this code working? It is coming up with the 'Type Mismatch'

error.

Thanks

Sub DeleteSheets()

For x = 1 To Worksheets.Count
If Worksheets(x).Name < "Menu" Or "Sage Export" Then
Worksheets(x).Delete
End If
Next x

End Sub



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
VB Delete Sheets LJones Excel Programming 3 July 27th 04 02:18 PM
delete all sheets except... caroline Excel Programming 4 May 22nd 04 04:29 PM
Delete Sheets Jahsonn Excel Programming 1 April 26th 04 01:42 PM
Delete Sheets SS[_3_] Excel Programming 2 February 5th 04 02:37 PM
Delete new sheets? ianripping[_27_] Excel Programming 1 January 17th 04 02:14 PM


All times are GMT +1. The time now is 09:33 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"