Consulting

Results 1 to 6 of 6

Thread: is there an opposite of 'selectedsheets'

  1. #1

    is there an opposite of 'selectedsheets'

    Anyone know if I can do the opposite of this?

    The only sheet I want to keep is always called 'Master'. Can that last command be something different to delete everything else?

    [VBA]Sub wkdel()
    '
    ' wkdel Macro
    '

    '
    Sheets("Table 1").Select
    ActiveWindow.SelectedSheets.Delete
    End Sub
    [/VBA]

  2. #2
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    Perhaps something like
    [vba]Dim oneSheet As Worksheet
    With ThisWorkbook
    If 1 < .Sheets.Count Then
    .Sheets(1 - CBool(.Sheets("Master").Index = 1)).Select True

    For Each oneSheet In .Sheets
    If oneSheet.Name <> "Master" Then oneSheet.Select False
    Next oneSheet
    End If
    End With
    [/vba]

    Or perhaps, you could copy Master to a new workbook, and save that workbook, deleting the old workbook that has many sheets.

  3. #3
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    or something like this.

    [vba]
    Dim ws As Worksheet

    Application.DisplayAlerts = False

    For Each ws In Worksheets
    If ws.Name <> "Master" Then ws.Delete
    Next ws

    Application.DisplayAlerts = True
    [/vba]
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  4. #4
    Many thanks this seems to work. Any idea how to get rid of the dialogue box confirming if i want to delete (t'these sheets contaion data... etc')

  5. #5
    oh, there it is. display alerts to false i guess

  6. #6
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    Quote Originally Posted by nicksinthemi
    oh, there it is. display alerts to false i guess
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

Posting Permissions

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