MultiSelect Listbox ouput problem

brianfosterblack

Active Member
Joined
Nov 1, 2011
Messages
251
I have this code in a command button in a Userform and in this I have a multiselect listbox named ClientList
I use the code below to put the contents selected in the listbox into column AW in my workbook.
In making adjustments to this I cut of the end of the code and the last 2 lines are showing an error. Can anyone assist with what has been cut off as this was working perfectly before.
One other question. Is there a way to prevent some names in the listbox from being selected"
VBA Code:
Private Sub CommandButton1_Click()
Dim x As Long
Dim varSelected() As String
Dim i As Integer

i = i - 1
With ClientList
    For x = 0 To .ListCount - 1
        If .Selected(x) Then
            i = i + 1
            ReDim Preserve varSelected(i)
            varSelected(i) = .List(x)
        End If
    Next x
End With

If i = -1 Then Exit Sub
Range(Cells(1, 49), Cells(UBound(varSelected) + 1, 49)) = _
WorksheetFunction.Transpose(Me.HideUnload FrmClientList

End Sub
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Best guess is that it should be
VBA Code:
Range(Cells(1, 49), Cells(UBound(varSelected) + 1, 49)) = _
WorksheetFunction.Transpose(varSelected)
 
Upvote 0
Solution
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,455
Messages
6,124,937
Members
449,196
Latest member
Maxkapoor

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