PDA

View Full Version : multiselect list box



Larren
06-10-2006, 09:40 AM
I hope someone can help, it's been awhile since I've used VBA. I'm trying to create a user form w/ multiselect list box, once the user as selected 2 or more options I want these to be copied to the worksheet in one cell seperated by comma's or at this point a space will do. All I can come up with is getting each selection in it's own cell which isn't what I'm needing. Any ideas, All help is much appriciated :think:

Norie
06-10-2006, 11:19 AM
Can you post what you have so far?

Larren
06-13-2006, 08:26 AM
Here's what I have for the submit button, any suggestions ?

Thank you sooo much!!


Private Sub cmdSubmit_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("KMS")
Dim lItem As Long
'find first empty row in database
iRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row


'copy the data to the database
ws.Cells(iRow, 1).Value = Me.cmbD.Value
ws.Cells(iRow, 2).Value = Me.cmbI.Value
ws.Cells(iRow, 3).Value = Me.ListBox1.Value
ws.Cells(iRow, 4).Value = Me.txtTW.Value


For lItem = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(lItem) = True Then

ws.Range("C65536").End(xlToRight) = ListBox1.List(lItem)
ListBox1.Selected(lItem) = False
End If
Next

'clear the data
Me.cmbD.Value = ""
Me.txtTW.Value = ""
Me.cmbI.Value = ""
Me.ListBox1.Value = ""

Me.cmbD.SetFocus

End Sub

Norie
06-13-2006, 08:43 AM
Try this.


For lItem = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(lItem) = True Then
strList = strList & ListBox1.List(lItem) & ","
ListBox1.Selected(lItem) = False
End If
Next
ws.Range("C65536").End(xlToRight) = Left(strList, Len(strList) - 1)

mdmackillop
06-13-2006, 08:56 AM
For commas,


Private Sub CommandButton1_Click()
For lItem = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(lItem) = True Then
strList = strList & ListBox1.List(lItem) & ", "
ListBox1.Selected(lItem) = False
End If
Next
ws.Range("C65536").End(xlToRight) = Left(strList, Len(strList) - 2)
End Sub

Larren
06-14-2006, 10:51 AM
Private Sub cmdSubmit_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("KMS")
Dim lItem As Long

'find first empty row in database
iRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row

For lItem = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(lItem) = True Then
ws.Range("C65536").End(xlUp)(2, 1) = ListBox1.List(lItem)
ListBox1.Selected(lItem) = False
End If
Next

This code is placing it all on different lines, when I tried the codes provided it's not pulling any of the selected information to the spread sheet. do you have any other ideas?? Thank you for your help

Norie
06-14-2006, 10:56 AM
Larren

The code worked fine for me.

Can you attach a sample workbook?

Larren
06-14-2006, 11:08 AM
Thank you so much for looking at this, I've probably got something messed up somewhere else causing the conflict I just don't know where.:dunno

lucas
06-14-2006, 11:22 AM
code in attachment is password protected....

Norie
06-14-2006, 11:24 AM
Larren

The VBA project is password protected in the attachment.:bug:

Larren
06-14-2006, 11:33 AM
sorry about that, the pw is aspect

Norie
06-14-2006, 11:40 AM
Larren

No it's not.:(

mdmackillop
06-14-2006, 11:58 AM
Try Aspect

Norie
06-14-2006, 12:06 PM
Larren

Did you actually change the code?

Have a look in IV65536.

By the way what does the add-in do, except cause Excel to slow down.:bug:

mdmackillop
06-14-2006, 12:06 PM
For lItem = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(lItem) = True Then
txt = txt & ListBox1.List(lItem) & ", "
ListBox1.Selected(lItem) = False
End If
Next

ws.Range("C65536").End(xlUp)(2, 1) = Left(txt, Len(txt) - 2)

Larren
06-14-2006, 12:09 PM
:115: sorry Norie, mdmackillop has it right it's Aspect

Larren
06-14-2006, 12:15 PM
Norie,

I just copied and pasted what had been posted when nothing transfered I put back in what I had

The add-in was a requirement from my manager, I didn't have much of a choice on that one

Larren
06-14-2006, 12:16 PM
mdmackillop,,,,Thank you, Thank you that did it. You all are wonderful I can't thank you enough for your help:mbounce: :bigkiss: