+ Reply to Thread
Results 1 to 10 of 10

Delete a Worksheet based on the cell value in another worksheet in the same workbook

  1. #1
    Registered User
    Join Date
    08-25-2014
    Location
    New York, New York
    MS-Off Ver
    Excel 2013
    Posts
    36

    Delete a Worksheet based on the cell value in another worksheet in the same workbook

    I have a workbook with 5 worksheets Sheet1, Sheet2, Sheet3, Sheet4, Sheet5.

    When cell C16 on Sheet1 states "YES" I would like Sheets Sheet2, Sheet3, Sheet4, Sheet5 to be deleted from the Workbook.

    Please help with the VBA Code for this.

    Thanks!

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Delete a Worksheet based on the cell value in another worksheet in the same workbook

    Hi, lhickerson,

    maybe try
    Please Login or Register  to view this content.
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Delete a Worksheet based on the cell value in another worksheet in the same workbook

    in Sheet1 Module
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    08-25-2014
    Location
    New York, New York
    MS-Off Ver
    Excel 2013
    Posts
    36

    Re: Delete a Worksheet based on the cell value in another worksheet in the same workbook

    Thanks for the quick response. OK - now I have more sheets to delete (lets say Sheet6 thru Sheet 20) but when I put the names in the line "If Target.Value = "YES" Then Sheets(Array("Sheet2", "Sheet3", "Sheet4", "Sheet5")).Delete" the code overruns to the next line of code. This causes and error. How do I fix this?

  5. #5
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Delete a Worksheet based on the cell value in another worksheet in the same workbook

    maybe so
    Please Login or Register  to view this content.

  6. #6
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Delete a Worksheet based on the cell value in another worksheet in the same workbook

    Hi, lhickerson,

    delete all other sheets?

    Please Login or Register  to view this content.
    Ciao,
    Holger

  7. #7
    Registered User
    Join Date
    08-25-2014
    Location
    New York, New York
    MS-Off Ver
    Excel 2013
    Posts
    36

    Re: Delete a Worksheet based on the cell value in another worksheet in the same workbook

    The sheet names are not actually Sheet6, Sheet7, etc. They are named sheets all with different names with no particular relation.

    Sheet names:

    Sheets(Array("Sealed Bid Invite", "Sub Bid Form (GMP)", "Bid Recording Sheet", "Rip and Read", "Cover Letter (GMP)", "TOC (GMP)", "Cost Summary (GMP)", "3A Pages ", "Summary of Allowances (GMP)", "Summary of Unbought Allow (GMP)", "
    ", "Alt Breakdown (GMP)", "CO-PCO Runsheet (GMP)", "CO-PCO Summary (GMP)","CO Breakdown (GMP)","AL Summary TOC (GMP)","Sub Scope Summary TOC (GMP)")).Delete

    Help!

  8. #8
    Registered User
    Join Date
    08-25-2014
    Location
    New York, New York
    MS-Off Ver
    Excel 2013
    Posts
    36

    Re: Delete a Worksheet based on the cell value in another worksheet in the same workbook

    I had a error in the code above - I hit "enter" in the middle - my mistake. I fixed it but the code didn't work. I am supposed to copy this code into the "Sheet1" tab in VBA right?

  9. #9
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Delete a Worksheet based on the cell value in another worksheet in the same workbook

    try Sheets(i).Delete instead of Sheets("Sheet" & i).Delete

  10. #10
    Registered User
    Join Date
    08-25-2014
    Location
    New York, New York
    MS-Off Ver
    Excel 2013
    Posts
    36

    Re: Delete a Worksheet based on the cell value in another worksheet in the same workbook

    The code is working - thanks very much for your help!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Delete & Hide Rows in a Worksheet based on the Value of a Cell in another Worksheet
    By lhickerson in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-12-2014, 09:53 AM
  2. [SOLVED] Delete rows on 2 different worksheets based on cell value from one worksheet
    By D.Lovell in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-08-2014, 04:14 AM
  3. Copy Worksheet from Another Workbook based on Cell Value
    By greasybob in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-02-2014, 05:52 PM
  4. Close Workbook,Rename Worksheet, Delete Worksheet.
    By Ariff_Chowdhury in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-24-2013, 09:21 PM
  5. [SOLVED] name worksheet based on value in cell from other workbook
    By E_T in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-02-2012, 04:10 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1