ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   range selection help needed (https://www.excelbanter.com/excel-programming/375231-range-selection-help-needed.html)

trward79

range selection help needed
 
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

JLGWhiz

range selection help needed
 
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.

"trward79" wrote:

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



All times are GMT +1. The time now is 10:02 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com