Problems with Listboxes and Selected items erro code 424 and Object rquired

Gypsy0710

New Member
Joined
Mar 7, 2016
Messages
1
Hello guys,

I have two listboxes, listbox1 and listbox2. In the first listbox the values have 3 columns with values are initial loaded. Then the user need to select items and then all values from the 3 columns need to be transferred to the other listbox2.

When I try to select the items, I'm always getting the error message: Object required...Error code 424

My code is here:

Option Explicit


Private Sub SelectItems_btn_Click()
Dim SelectedItems As String
Dim i As Integer
Dim ListBox2i As Integer
ListBox2i = 0
For i = 0 To ListBox1.ListCount - 1

If ListBox1.Selected(i) = True Then

Me.ListBox2.AddItem
Me.ListBox2.List(ListBox2i, 0) = ListBox1.List(i, 0).Value
Me.ListBox2.List(ListBox2i, 1) = ListBox1.List(i, 1).Value
Me.ListBox2.List(ListBox2i, 2) = ListBox1.List(i, 2).Value
ListBox2i = ListBox2i + 1
End If

Next


End Sub

Private Sub UserForm_Initialize()
ListBox1.MultiSelect = 2
ListBox2.MultiSelect = 2

Dim RowsNumber As Integer
Dim RowsNumberOnly As Integer
Dim i As Integer
Dim Customers As Long
Dim customersloop As Long
Dim test As String
RowsNumber = FunctionCount.calculateRows
RowsNumberOnly = FunctionCount.calculateRowsValue

ListBox1.ColumnCount = 3
ListBox1.ColumnWidths = "50;50;50"

ListBox2.ColumnCount = 3
ListBox2.ColumnWidths = "50;50;50"


Customers = 10
i = 0

For customersloop = Customers To RowsNumber
ListBox1.AddItem
ListBox1.List(i, 0) = Sheets("Test").Range("J" & customersloop).Value
ListBox1.List(i, 1) = Sheets("Test").Range("K" & customersloop).Value
ListBox1.List(i, 2) = Sheets("Test").Range("L" & customersloop).Value
i = i + 1
Next


End Sub


Best regards and thanks in advance!

Matthias
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

Forum statistics

Threads
1,216,175
Messages
6,129,312
Members
449,499
Latest member
HockeyBoi

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