Excel VBA Listbox

Joined
Jun 25, 2006
Messages
2
Reaction score
0
Hi All,

I have created a Listbox on a Userform. the Listbox properties are as folows:

Name: SectorList
MultiSelect: fmMultiSelectMulti

I am trying to see which items were selected and then for these items i want to put their value into a cell. My problem is that once it finds the first item that was selected, it puts its value into the relevant cell but then seems to mark all the other selected items as not selected.

The weird thing is, for testing purposes, if i dont actually assign the selected items value to a cell then there is no problems!

The code is as follows:

For lItem = 0 To sectorList.ListCount - 1
If sectorList.Selected(lItem) Then
ActiveCell.Value = sectorList.List(lItem)
ActiveCell.Offset(1, 0).Range("A1").Select
End If
Next

Any help would be really appreciated!

Shakeel
 
Joined
May 18, 2006
Messages
6
Reaction score
0
Not sure but I'd be willing to bet that the reason it only reports the first is because you are using the .Select command to move through your list of cells. Try using Cells(Row#,Col#).Value with a variable in the row # that you increase by 1 after you insert the value. Good luck!



shakeel_sadiq said:
Hi All,

I have created a Listbox on a Userform. the Listbox properties are as folows:

Name: SectorList
MultiSelect: fmMultiSelectMulti

I am trying to see which items were selected and then for these items i want to put their value into a cell. My problem is that once it finds the first item that was selected, it puts its value into the relevant cell but then seems to mark all the other selected items as not selected.

The weird thing is, for testing purposes, if i dont actually assign the selected items value to a cell then there is no problems!

The code is as follows:

For lItem = 0 To sectorList.ListCount - 1
If sectorList.Selected(lItem) Then
ActiveCell.Value = sectorList.List(lItem)
ActiveCell.Offset(1, 0).Range("A1").Select
End If
Next

Any help would be really appreciated!

Shakeel
 
Joined
Jun 25, 2006
Messages
2
Reaction score
0
Thanks for the reply AhrenL, i did get around my initial problem but im still going to try what you've suggested 'cus im curious!

Ta

Shakeel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top