Listbox & Labelbox
Listbox & Labelbox
(OP)
I have a question and I am stumped.
I have a userform1 that is filled then when a label28 is pressed a userform pops up with a listbox (multi selection). and a label underneath for the merging of the selections. Now I am stuck trying to make this work and also how would I make it that the label on Userform1 = userform2 label.
Here is my code thus far, just can't seem to get it to work.
Private Sub Userform_Initialize()
With ListBox1
.MultiSelect = fmMultiSelectMulti
ListBox1.List = Sheet4.Range("AL2:AL166").Value
End With
End Sub
Private Sub OK_Click()
Dim I As Long
Dim strCont As String
For I = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(I) Then
strCont = strCont & ListBox1.List(I) & "//"
ListBox1.Selected(I) = False
End If
Next I
Label1.Caption = Left(strCont, Len(strCont) - 1)
Me.Range("CP" & Sel_Row).Value ' THIS SEEMS TO BE THE PROBLEM
Unload UserForm2
End Sub
If anyone can help me or give me a suggestion, I would greatly appreciate it.
Regards
Bill
I have a userform1 that is filled then when a label28 is pressed a userform pops up with a listbox (multi selection). and a label underneath for the merging of the selections. Now I am stuck trying to make this work and also how would I make it that the label on Userform1 = userform2 label.
Here is my code thus far, just can't seem to get it to work.
Private Sub Userform_Initialize()
With ListBox1
.MultiSelect = fmMultiSelectMulti
ListBox1.List = Sheet4.Range("AL2:AL166").Value
End With
End Sub
Private Sub OK_Click()
Dim I As Long
Dim strCont As String
For I = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(I) Then
strCont = strCont & ListBox1.List(I) & "//"
ListBox1.Selected(I) = False
End If
Next I
Label1.Caption = Left(strCont, Len(strCont) - 1)
Me.Range("CP" & Sel_Row).Value ' THIS SEEMS TO BE THE PROBLEM
Unload UserForm2
End Sub
If anyone can help me or give me a suggestion, I would greatly appreciate it.
Regards
Bill





RE: Listbox & Labelbox
CODE
The statement Me.Range("CP" & Sel_Row).Value might return something, but you are not doing anything with or to it. Also, I don't see how this is related to the stated goal.
I think there are more sophisticated ways, but a public variable should do the trick.
CODE
Public myLabelText as String
myLabelText = userform1.label28.text
Somewhere in Userform2:
userform2.label##.text = myLabelText
RE: Listbox & Labelbox
They have a very active vba forum.
=====================================
Eng-tips forums: The best place on the web for engineering discussions.