Consulting

Results 1 to 4 of 4

Thread: Solved: Keep the only Sheet

  1. #1
    Banned VBAX Regular
    Joined
    Feb 2009
    Posts
    51
    Location

    Solved: Keep the only Sheet

    When I open an Excel workbook, I want to keep only one sheet name "Hello" and I want to delete other sheets which were created in last session.

    Therefore, Excel should delete all other sheets, except one sheet.


  2. #2
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,101
    Location
    Try the following on a copy of a workbook, and if it works to your satisfaction then we only need to change the action to a BeforeClose event and reside the code within the This Workbook module

    [vba]Sub deletesheets()
    Dim ws As Worksheet
    Application.DisplayAlerts = False
    For Each ws In ThisWorkbook.Worksheets
    If ws.Name <>"Hello" Then ws.Delete
    Next ws
    End Sub
    [/vba]
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  3. #3
    Banned VBAX Regular
    Joined
    Feb 2009
    Posts
    51
    Location

    Thumbs up Charts too

    Thanks ...

    There can be Charts also along with sheets. How to delete Charts?
    Could there be anything else, along with Charts?
    How to mark this thread as "Solved"?

    Thanks ...


    Quote Originally Posted by Aussiebear
    Try the following on a copy of a workbook, and if it works to your satisfaction then we only need to change the action to a BeforeClose event and reside the code within the This Workbook module

    [vba]Sub deletesheets()
    Dim ws As Worksheet
    Application.DisplayAlerts = False
    For Each ws In ThisWorkbook.Worksheets
    If ws.Name <>"Hello" Then ws.Delete
    Next ws
    End Sub
    [/vba]

  4. #4
    Banned VBAX Regular
    Joined
    Feb 2009
    Posts
    51
    Location

    Solved: Keep the only Sheet

    Thanks...

    Attached Files Attached Files
    Last edited by sukumar.vb; 08-28-2011 at 04:46 PM. Reason: Attachment

Posting Permissions

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