Populate an array with items in listbox

Eclektics

New Member
Joined
Jun 9, 2015
Messages
24
Hi All,

I have a user form with 2 list boxes, the left box is populated and the right is blank, users will select values on the left and move them to the right list box.

When they hit the command button I want all the selected items in the right list box (ListBox2) to populate an array that I can then use to filter the data in the workbook.

Here is my code so far, it errors on the line 'ListBox2.List = LArray'. Any help would be greatly appreciated. :)

Code:
Private Sub cmdSelect_Click()
Dim LArray As Long
Dim lrow, LRowII As Long
ListBox2.List = LArray
Dim ds, ws As Worksheet
Set ws = Sheet2
Set ds = Sheets("Excluded Data")
lrow = ws.Cells(ws.Rows.Count, "A:A").End(xlUp).Row
LRowII = ds.Cells(ds.Rows.Count, "A:A").End(xlUp).Row
With ds
    .Range("$A:$HH").AutoFilter field:=1, Criteria1:=LArray
    .Range("$A$2:$HH$" & LRowII).SpecialCells(xlCellTypeVisible).Copy Destination:=ws.Range("A" & lrow + 1)
    .Range("$A$2:$HH$" & LRowII).SpecialCells(xlCellTypeVisible).EntireRow.Delete
    .ShowAllData
End With
End Sub
 
Like I said, filtering by an array in code is tricky.

Have you checked what's actually in LArray?
 
Upvote 0

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Try
Code:
.Range("$A:$HH").AutoFilter 1, Application.Transpose(LArray), xlFilterValues
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

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