+ Reply to Thread
Results 1 to 13 of 13

Userform List to Delete Sheets after specific sheet

  1. #1
    Registered User
    Join Date
    03-05-2020
    Location
    Stoke on Trent, England
    MS-Off Ver
    Excel 2016
    Posts
    59

    Userform List to Delete Sheets after specific sheet

    Hello All,

    I have created a button which brings up a userform (userform2) with a list and button on it. I need the contents of the List to be populated with all the sheet names which exist after the Performance Hub Sheet. On selection from the userform list I then need to be able to delete the selected sheet when hitting the userform button.

    Any ideas on how I can make this work please?
    Attached Files Attached Files

  2. #2
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Userform List to Delete Sheets after specific sheet

    Something like this?

    Please Login or Register  to view this content.
    If you don't want the warning about deleting the sheet, then you could use Application.DisplayAlerts = False before the delete line, and right after it set that back to True
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  3. #3
    Registered User
    Join Date
    03-05-2020
    Location
    Stoke on Trent, England
    MS-Off Ver
    Excel 2016
    Posts
    59

    Re: Userform List to Delete Sheets after specific sheet

    Thanks for the reply. Just tried it but it throws up an error when I click the Delete Focus list button saying Compile error, Invalid outside procedure.

  4. #4
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Userform List to Delete Sheets after specific sheet

    hmm doesn't sound right... did you paste ALL the code I posted into your userform?

  5. #5
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Userform List to Delete Sheets after specific sheet

    If you missed a sub heading or end sub, that could cause that error. It usually means you have code that is not INSIDE a sub, but I didn't post any lines not inside a sub.
    I can't test with that sheet because there is no sheet called Focus List on what you attached. However if I delete Maka 1 or PERFORMANCE HUB, the code worked perfectly.

  6. #6
    Registered User
    Join Date
    03-05-2020
    Location
    Stoke on Trent, England
    MS-Off Ver
    Excel 2016
    Posts
    59

    Re: Userform List to Delete Sheets after specific sheet

    My Bad Yes. I have now split the code and put the button code where it should be.
    The user form doesn't find any values though just remains blank?

  7. #7
    Registered User
    Join Date
    03-05-2020
    Location
    Stoke on Trent, England
    MS-Off Ver
    Excel 2016
    Posts
    59

    Re: Userform List to Delete Sheets after specific sheet

    The Focus list is the sheet that is generated by another routine. Maka 1 is a focus list sheet and so is SUV AutoPolish. The idea is that I can create as many as I like and the userform list will identify them and allow me the option to delete if required.

  8. #8
    Registered User
    Join Date
    03-05-2020
    Location
    Stoke on Trent, England
    MS-Off Ver
    Excel 2016
    Posts
    59

    Re: Userform List to Delete Sheets after specific sheet

    So anything I add which is to the right of the performance hub sheet I need to have in the list and be able to select and delete.

  9. #9
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Userform List to Delete Sheets after specific sheet

    Arkadi's code works for me, based on my interpretation of your need.

    For what it's worth there are often many ways of accomplishing the same thing in Excel, especially when it comes to VBA.

    With that in mind, here's my version of code to do what (I think) you mean.

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

    Does that do what you expect?

    BSB
    Attached Files Attached Files

  10. #10
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Userform List to Delete Sheets after specific sheet

    Note my code will display any sheet name that's not "PERFORMANCE HUB" and is not hidden. I would suggest you avoid relying on anything such as sheet tab order. It's very easy to accidentally move a sheet position in the tab list and that could throw the whole thing out.

    BSB

  11. #11
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Userform List to Delete Sheets after specific sheet

    There should be no need to "split" my code... it all goes inside the userform. If you put the initialize code in a standard module, it would not run, and nothing would load into the combobox.

  12. #12
    Registered User
    Join Date
    03-05-2020
    Location
    Stoke on Trent, England
    MS-Off Ver
    Excel 2016
    Posts
    59

    Re: Userform List to Delete Sheets after specific sheet

    Thanks Both for your help, yes this works great.

  13. #13
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Userform List to Delete Sheets after specific sheet

    Thanks for the rep and feedback, and marking the thread as solved

+ 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. VBA loop to insert and delete worksheets in a specific sheet within a list
    By supppy in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-09-2014, 09:02 PM
  2. [SOLVED] Macro to delete sheets in a workbook if sheet does not contain specific word
    By elgato74 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-26-2014, 02:08 PM
  3. getting specific data from several sheets into 1 sheet as a master list
    By rod642 in forum Excel Formulas & Functions
    Replies: 16
    Last Post: 01-23-2014, 10:58 AM
  4. [SOLVED] Vlookup in UserForm - Get Input from listbox, Lookup in specific table from specific sheet
    By s2jrchoi in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-30-2013, 09:00 AM
  5. delete range in specific sheets
    By timtim89 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-24-2012, 01:54 PM
  6. Add and Delete Sheets based on contents of list located in the first sheet
    By gophins in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-09-2012, 03:50 PM
  7. Replies: 29
    Last Post: 11-22-2010, 03:51 PM

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