List Worksheets and select one (or more)

sspicer

New Member
Joined
Jun 27, 2008
Messages
48
I am sorry if I am repeating a thread here, but I've tried to find something that will help me, and can't.

I have a model which produces a new worksheet each time it is run - and old sheets are hidden from the user.

I need to write some code that will take the names of all spreadsheets and list them in a userform (or similar) so that the user can then click on the ones they wish to delete and press delete (i.e. be able to select more than one if they wish).

I am happy with being able to assign the commands to buttons once sheet names have been selected, but I don't known how to get the names of the sheets in the form in the first place.

Any help? Please feel free to point me in the direction of another thread if I've missed something.

Thanks for your help in advance.
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Create a userform with a listbox set to multiselect

Put this code in the userfrom code module it will build your list of sheets

Code:
Option Explicit
Private Sub UserForm_Initialize()
    Dim sht As Worksheet
    ListBox1.MultiSelect = fmMultiSelectMulti
    For Each sht In Worksheets
        ListBox1.AddItem sht.Name
    Next sht
End Sub
 
Upvote 0
Next: Place a button on the sheet to activate the deletion of the selected sheets to be deleted.

Place this code in the userform code module

Code:
Private Sub CommandButton1_Click()
Dim lItem As Long
    For lItem = 0 To ListBox1.ListCount - 1
        If ListBox1.Selected(lItem) = True Then
            Sheets(ListBox1.List(lItem)).Delete
            ListBox1.Selected(lItem) = False
        End If
    Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,148
Messages
6,123,301
Members
449,095
Latest member
Chestertim

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top