VBA Delete current work sheet if not a specific title
Results 1 to 9 of 9

Thread: VBA Delete current work sheet if not a specific title

  1. #1
    New Member
    Join Date
    Jun 2019
    Posts
    32
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default VBA Delete current work sheet if not a specific title

    Hi.

    Im needing help for VBA to delete current work sheet if not a specific name.

    Quite a lot of examples out, but can't seem to adapt.

    Thanks.

  2. #2
    Board Regular
    Join Date
    Sep 2016
    Posts
    2,560
    Post Thanks / Like
    Mentioned
    36 Post(s)
    Tagged
    1 Thread(s)

    Default Re: VBA Delete current work sheet if not a specific title

    Code:
    Application.DisplayAlerts = False
    If ActiveSheet.Name = "Sheet1" Then ActiveSheet.Delete
    Application.DisplayAlerts = True

  3. #3
    MrExcel MVP Rick Rothstein's Avatar
    Join Date
    Apr 2011
    Location
    New Jersey, USA
    Posts
    35,069
    Post Thanks / Like
    Mentioned
    92 Post(s)
    Tagged
    33 Thread(s)

    Default Re: VBA Delete current work sheet if not a specific title

    Quote Originally Posted by footoo View Post
    Code:
    Application.DisplayAlerts = False
    If ActiveSheet.Name = "Sheet1" Then ActiveSheet.Delete
    Application.DisplayAlerts = True
    The OP said "delete current work sheet if not a specific name", so I think your equal sign (=) should be a not equal sign (<>).
    Rick's "mini" blog... http://www.excelfox.com/forum/f22/
    .
    Want to post a small screen shot? See Part B here.

  4. #4
    New Member
    Join Date
    Jun 2019
    Posts
    32
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA Delete current work sheet if not a specific title

    Thanks footoo, but what if i dont want it to delete the active sheet if its a specific name.

    For example, i could have sheet1, sheet2, sheet3. Each page has this code to delete, but i dont want it to delete if the name is sheet1

  5. #5
    Board Regular
    Join Date
    Sep 2016
    Posts
    2,560
    Post Thanks / Like
    Mentioned
    36 Post(s)
    Tagged
    1 Thread(s)

    Default Re: VBA Delete current work sheet if not a specific title

    See post # 3

  6. #6
    New Member
    Join Date
    Jun 2019
    Posts
    32
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA Delete current work sheet if not a specific title

    Perfect. Thanks all.

  7. #7
    New Member
    Join Date
    Jun 2019
    Posts
    32
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA Delete current work sheet if not a specific title

    Actually, the code works and delets as require, but i get this error

    run-time error '-2147221080 (800401a8) automation error

    Not sure why?

  8. #8
    Board Regular
    Join Date
    Sep 2016
    Posts
    2,560
    Post Thanks / Like
    Mentioned
    36 Post(s)
    Tagged
    1 Thread(s)

    Default Re: VBA Delete current work sheet if not a specific title

    Do you have the macro containing the code in the sheet module being deleted?
    If so, put in a normal module instead.

  9. #9
    New Member
    Join Date
    Jun 2019
    Posts
    32
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA Delete current work sheet if not a specific title

    Yep, that seemed to have solved.

    Thanks.

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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