listbox remove all items

sspicer

New Member
Joined
Jun 27, 2008
Messages
48
I have a userform in my model which displays a list of sheets within the spreadsheet, these can be selected and then either the "delete" button pressed or the "view" button pressed.

The first time this is done it works a charm - perfect!
however, the second time that it opens all the old sheets are still in there even though they've been deleted. Do i need to delete all the previous items in the list, and if so - how?!

I've tried everything i can think of from listbox1.clear to for each item in listbox item.remove etc... Help!

Code:
Private Sub UserForm_Initialize()

Application.Calculate

Dim sht As Worksheet
Dim NoSheets As Integer
ListBox1.MultiSelect = fmMultiSelectMulti
For Each sht In Worksheets
Select Case sht.Name
Case "Control"
Case "Scheme Input"
Case "Member Input"
Case "Member Data"
Case "Developer Notes"
Case "Working Info"
Case "Claims Input"
Case Else
ListBox1.AddItem sht.Name
End Select
Next sht
'greys out the action buttons if nothing has been selected
If ListBox1.ListIndex = -1 Then
With UserForm1
.CommandButton1.Enabled = False
.CommandButton2.Enabled = False
End With
Else
With UserForm1
.CommandButton1.Enabled = True
.CommandButton2.Enabled = True
End With

End If

End Sub
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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