Common Function for getting userform information
Sub Test()
Dim i As Long, n As Long
Dim s As String
Dim arr
Dim lb As MSForms.ListBox
Set lb = UserForm1.ListBox1
n = getSelected(lb, arr)
If n = -1 Then
s = "no items selected"
Else
s = arr(0)
For i = 1 To UBound(arr)
s = s & vbCr & arr(i)
Next
End If
MsgBox s
End Sub
Function getSelected(lb As MSForms.ListBox, arr) As Long
Dim i As Long, idx As Long
idx = -1
ReDim arr(0 To lb.ListCount - 1)
For i = 0 To lb.ListCount - 1
If lb.Selected(i) Then
idx = idx + 1
arr(idx) = lb.List(i)
End If
Next
If idx = 0 And idx < UBound(arr) Then
ReDim Preserve arr(0 To idx)
End If
getSelected = idx
End Function
Regards,
Peter T
"Danny" wrote in message
...
Hi,
My macro has a lot of userform and multi listbox within userform (each
userform has unique name). how can I use a function to get the
selected items in different listbox?
eg.
fmMyPlot.lb_Prof_xAxis
fmMyPlot.lb_Prof_y1Axis
fmMyPlot.lb_Std_Gp
fmMyPlot.lb_Std_Series
fmMyTemplate.lb_temp1
fmMyTemplate.lb_temp2
any ideas? thx
|