listbox question

JohnSearcy

Board Regular
Joined
Feb 6, 2006
Messages
101
I am new to using listboxes and am expirementing with code and figuring stuff out here and there, but I am having trouble with one thing. What code enables the automatic selection of all items within the listbox?

Sample (that obviously doesn't work):

For X = 0 To listbox1.ListCount - 1
listbox1.SetSelected (X) (and I tried Select (X))
Next X

Most likely very simple - just haven't hit the right coding yet.

Thanks,
John
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
You were close.
Code:
Private Sub UserForm_Initialize()
  Dim i As Integer
  With ListBox1
    .MultiSelect = fmMultiSelectMulti
    .List = Array("1", "2", "3")
    For i = 0 To .ListCount - 1
      .Selected(i) = True
    Next i
  End With
End Sub
 
Upvote 0
.List is a quick way to fill the listbox rather than one at a time. Obviously, you are probably filling your listbox in some other manner.
 
Upvote 0

Forum statistics

Threads
1,224,595
Messages
6,179,798
Members
452,943
Latest member
Newbie4296

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