range selection help needed

T

trward79

I have a form that I use to select data from a range on the page which works
fine, and if it is selected from the list, it moves to a second box, and then
when Run is clicked, it processes the data from ListBox2 to the range of A2.
This is where I have the issue of selecting all the values of the list Box
and copying them to the sheet. I also have a problem making them
multi-select. I am including my code here to see if anyone can help.

Private Sub CommandButton2_Click()
Worksheets("Auto_Working").Select
Range("A2:A1502").ClearContents
' This is where it only moves the value if it is selected in the ListBox2,
and not all
' values like I need it to. Also ListBox2 is not Multi-Select
WorkSheets("AutoWorking").Range("A2").Value = ListBox2.Value
Moudule1.Added_Employee
End Sub

'This retrieves values from worksheet to listbox1
Private Sub UserForm_Initialize()
Dim myCell As Range
Dim myRng As Range
Dim myWord As String

myWord= "Employee"
With Worksheets("Auto_Working")
Set myRng = .Range("A1", .Cells(.Rows.Count, "A").End(xlUp))
End With
For Each myCell In myRng.Cells
If LCase(Left(myCell.Value, Len(myWord))) <> LCase(myWord) Then
Me.ListBox1.AddItem myCell.Value
End If
Next myCell
End Sub

'This copies values selected from listbox1 to listbox2
Private Sub CommandButton1_Click()
If Me.ListBox1.Value <> "" Then
Me.ListBox2.AddItem Me.ListBox1.Value
TextBox1.Value = Me.ListBox1.Value
End If
End Sub
 
J

JLGWhiz

The multiselect property is set by opening the VBE, selecting the userform
your listbox is on and then selecting the listbox. The properties window
should appear on the lower left where you can then set your multiselect to
true.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top