Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
VB Delete Sheets | Excel Programming | |||
delete all sheets except... | Excel Programming | |||
Delete Sheets | Excel Programming | |||
Delete Sheets | Excel Programming | |||
Delete new sheets? | Excel Programming |