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

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

Forum statistics

Threads
1,223,229
Messages
6,170,881
Members
452,364
Latest member
springate

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