Consulting

Results 1 to 3 of 3

Thread: Delete visible sheets except sheet1

  1. #1
    VBAX Regular
    Joined
    Jan 2011
    Posts
    62
    Location

    Delete visible sheets except sheet1

    Hi All,

    I am trying to delete the visble sheets except sheet 1 i manage to get delete all workbook except sheet1 any one can pleae modify . i need to delete visble sheets except sheet 1 all the hidden sheet will remain in the workbook.

    [VBA]Sub DeleteSheets()

    Dim wksCurr As Worksheet

    Application.DisplayAlerts = False
    For Each wksCurr In ThisWorkbook.Worksheets
    If wksCurr.Index <> 1 Then
    wksCurr.Delete
    End If
    Next wksCurr
    Application.DisplayAlerts = True

    End Sub[/VBA]

    Thanks
    farrukh

  2. #2
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    Something akin to this:
    [vba]Sub DeleteSheets()

    Dim wksCurr As Worksheet

    Application.DisplayAlerts = False
    For Each wksCurr In ThisWorkbook.Worksheets
    If wksCurr.Index <> 1 And wksCurr.Visible = xlSheetVisible Then
    wksCurr.Delete
    End If
    Next wksCurr
    Application.DisplayAlerts = True

    End Sub [/vba]
    Be as you wish to seem

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Sub DeleteSheets()
    Dim wksCurr As Worksheet

    Application.DisplayAlerts = False

    With ThisWorkbook

    For Each wksCurr In .Worksheets

    If wksCurr.Index = 1 Then

    wksCurr.Visible = xlSheetVisible 'just in case
    ElseIf wksCurr.Visible = xlSheetVisible Then

    wksCurr.Delete
    End If
    Next wksCurr
    End With

    Application.DisplayAlerts = True
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •