+ Reply to Thread
Results 1 to 12 of 12

display Selection Box of each/every Worksheet on open - delete unchecked sheets...

  1. #1
    Registered User
    Join Date
    10-04-2017
    Location
    Northamptonshire, England
    MS-Off Ver
    2016
    Posts
    3

    display Selection Box of each/every Worksheet on open - delete unchecked sheets...

    Hi Gurus,

    Is there a way I can have a checklist option for each and every sheet within workbook:

    Basically, I want to:

    1.) Open the Workbook - on open, have an 'option box' pop up and list every available sheet [by name] in the entire workbook.
    2.) I then want to select the sheets I want to keep (and then work on) on this occasion, and have all the unchecked - therefore unwanted - sheets deleted.
    3.) If i can also have a text search/replace at this point it would be amazing: find/replace TITLE [workbook] with: "whatever i choose"

    That's all folks!

    I have a geopostcode sheet that is hidden within the workbook, that i need to still be there after the above - FYI

    Any help is greatly appreciated,

    Thanks

    Alix

  2. #2
    Valued Forum Contributor
    Join Date
    08-07-2014
    Location
    Quito, Ecuador
    MS-Off Ver
    Excel 2016 & 365, Windows 10
    Posts
    511

    Re: display Selection Box of each/every Worksheet on open - delete unchecked sheets...

    Hi @ Alixnb1

    You can use two macros for doing that:
    The first one must be copied to the "ThisWorkbook" module
    The second one must be copied to a Standard module.

    Then save the book.
    From now whenever you open the book, a new sheet named MyControl is created, with a list of all sheets ( including hidden ones).
    you can check the boxes and run the second macro to delete the marked sheets.
    Remember to always check MyControl sheet.

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Barriers are there for those who don't want to dream

  3. #3
    Registered User
    Join Date
    10-04-2017
    Location
    Northamptonshire, England
    MS-Off Ver
    2016
    Posts
    3

    Re: display Selection Box of each/every Worksheet on open - delete unchecked sheets...

    Thanks for the speedy support vichopalacios...

    To be a nightmare, the code is working the wrong way round... I need for people to quickly select which pages to keep, and then have the code delete the unchecked sheets?

    Also, is it possible to get this into a userform popup on open?

    Thank you

  4. #4
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: display Selection Box of each/every Worksheet on open - delete unchecked sheets...

    @vichopalacios, so got some questions for you.

    yes it is working backwards, whatever you check, that gets deleted. also if you save the workbook, close it and reopen it, it fails on this line:

    Please Login or Register  to view this content.
    so i put this in its place so that it doesn't error out on the MyControl sheet

    Please Login or Register  to view this content.
    now the question is how to update MyControl tab so that when it deletes the sheets, it updates the page to reflect that.

    thoughts?
    Last edited by dmcgov; 10-06-2017 at 08:58 AM.

  5. #5
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,293

    Re: display Selection Box of each/every Worksheet on open - delete unchecked sheets...

    Change this line
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    Works here for me but haven't tried loading to userform yet

    and just let the code delete the MyControl worksheet

  6. #6
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: display Selection Box of each/every Worksheet on open - delete unchecked sheets...

    so my workbook is now functional, use the following code:

    Please Login or Register  to view this content.
    and

    Please Login or Register  to view this content.

  7. #7
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,293

    Re: display Selection Box of each/every Worksheet on open - delete unchecked sheets...

    Try workbook here

    Userform1 code
    Please Login or Register  to view this content.
    Module code
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by nigelog; 10-06-2017 at 11:24 AM.

  8. #8
    Valued Forum Contributor
    Join Date
    08-07-2014
    Location
    Quito, Ecuador
    MS-Off Ver
    Excel 2016 & 365, Windows 10
    Posts
    511

    Re: display Selection Box of each/every Worksheet on open - delete unchecked sheets...

    Hi @dmcgov
    I have a couple of comments here:
    Please Login or Register  to view this content.
    This line of code does nothing, because the name of Worksheets("MyControl") will never be ""
    Better to check if there is that sheet, and delete it.
    If you do that, you don't need to duplicate the code in the Clean macro.
    so, please try with the following

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    10-04-2017
    Location
    Northamptonshire, England
    MS-Off Ver
    2016
    Posts
    3
    Quote Originally Posted by vichopalacios View Post
    Hi @dmcgov
    I have a couple of comments here:
    Please Login or Register  to view this content.
    This line of code does nothing, because the name of Worksheets("MyControl") will never be ""
    Better to check if there is that sheet, and delete it.
    If you do that, you don't need to duplicate the code in the Clean macro.
    so, please try with the following

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Thank you so much... Im almost there (sorry)

    Can you idiot guide me for which code goes where please? I.e put this into a module... That into the workbook... Etc

    Also, do I need a specific box on the userform to show the selection list?

    Sorry, and thank you all for your input!

  10. #10
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,293

    Re: display Selection Box of each/every Worksheet on open - delete unchecked sheets...

    @alixbb1 did you look at workbook I posted - may save you time


    One userform called Userform1

    One Listbox called Listbox1

    One command button called CommandButton1
    Last edited by nigelog; 10-06-2017 at 12:41 PM.

  11. #11
    Valued Forum Contributor
    Join Date
    08-07-2014
    Location
    Quito, Ecuador
    MS-Off Ver
    Excel 2016 & 365, Windows 10
    Posts
    511

    Re: display Selection Box of each/every Worksheet on open - delete unchecked sheets...

    Hi @Alixnb1

    You have been presented 2 different solutions for your request:
    the first one is a "In sheet", the second one is a independent "UserForm"

    If you want to go with the in sheet:
    you need to paste the final "Private Sub Workbook_Open()" in the "Thisworkbook" module,
    and the "Sub CleanSheets()" in a standard Module

    If you want to go with the second one:
    you need to create a new Userform,
    assign to its module the "Private Sub UserForm_Initialize()" ,
    and then paste the "Sub CleanSheets()" ... from nigelog post #7... into a standard Module
    and finally paste the next code into your "Thisworkbook" module

    Please Login or Register  to view this content.

  12. #12
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,293

    Re: display Selection Box of each/every Worksheet on open - delete unchecked sheets...

    Ta vicjopolacius
    The form and module could be exported from example into the workbook and imported into their workbook
    Leaving just rhe workbook open routine

+ 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. [SOLVED] Using Command Button to Open Worksheet Based on ComboBox Selection
    By laura_jean in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-10-2014, 09:23 AM
  2. [SOLVED] Delete Worksheet Row By Matching Selection in a Multi Column ListBox
    By sparkoft in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-26-2013, 11:49 PM
  3. Checkbox When Unchecked Hides Worksheet
    By dcarn in forum Excel General
    Replies: 1
    Last Post: 12-06-2012, 06:57 PM
  4. Replies: 25
    Last Post: 05-27-2011, 06:48 PM
  5. Selection of cells in multiple sheets and delete the data in them
    By kolovel in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-03-2011, 06:17 AM
  6. Replies: 14
    Last Post: 04-04-2006, 08:00 PM
  7. Replies: 3
    Last Post: 10-07-2005, 05:05 AM

Tags for this Thread

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