ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   List Values to TextBox (https://www.excelbanter.com/excel-programming/408907-list-values-textbox.html)

Patrick C. Simonds

List Values to TextBox
 
Have a UserForm with a number of TextBoxes. When I click on TextBox1 it
opens a new Userform which displays a ListBox What I need to know is when I
close the ListBox Userform, how do I get the selected values (which are in
Column 1,5 and 6) into TextBox 1, 2 and 3.


Dave Peterson

List Values to TextBox
 
I used this code to show the second userform2:

Me.Hide
UserForm2.Show
Me.Show

Then I used this code behind UserForm2:

Option Explicit
Private Sub CommandButton1_Click()
With Me.ListBox1
If .ListIndex < 0 Then
'nothing selected, same as cancel?
Else
UserForm1.TextBox1.Value = .List(.ListIndex, 0)
UserForm1.TextBox2.Value = .List(.ListIndex, 1)
UserForm1.TextBox3.Value = .List(.ListIndex, 2)
End If
End With
Unload Me
End Sub
Private Sub CommandButton2_Click()
Unload Me
End Sub
Private Sub UserForm_Initialize()
Dim myRng As Range

With Worksheets("sheet1")
Set myRng = .Range("a1:G5")
End With

With Me.ListBox1
.List = myRng.Value
.ColumnCount = myRng.Columns.Count
.MultiSelect = fmMultiSelectSingle
End With

With Me.CommandButton1
.Default = True
.Caption = "Ok"
End With

With Me.CommandButton2
.Cancel = True
.Caption = "Cancel"
End With

End Sub


"Patrick C. Simonds" wrote:

Have a UserForm with a number of TextBoxes. When I click on TextBox1 it
opens a new Userform which displays a ListBox What I need to know is when I
close the ListBox Userform, how do I get the selected values (which are in
Column 1,5 and 6) into TextBox 1, 2 and 3.


--

Dave Peterson

Patrick C. Simonds

List Values to TextBox
 
Thank you,

Any way those ListValues could be formated as 00:00?

"Dave Peterson" wrote in message
...
I used this code to show the second userform2:

Me.Hide
UserForm2.Show
Me.Show

Then I used this code behind UserForm2:

Option Explicit
Private Sub CommandButton1_Click()
With Me.ListBox1
If .ListIndex < 0 Then
'nothing selected, same as cancel?
Else
UserForm1.TextBox1.Value = .List(.ListIndex, 0)
UserForm1.TextBox2.Value = .List(.ListIndex, 1)
UserForm1.TextBox3.Value = .List(.ListIndex, 2)
End If
End With
Unload Me
End Sub
Private Sub CommandButton2_Click()
Unload Me
End Sub
Private Sub UserForm_Initialize()
Dim myRng As Range

With Worksheets("sheet1")
Set myRng = .Range("a1:G5")
End With

With Me.ListBox1
.List = myRng.Value
.ColumnCount = myRng.Columns.Count
.MultiSelect = fmMultiSelectSingle
End With

With Me.CommandButton1
.Default = True
.Caption = "Ok"
End With

With Me.CommandButton2
.Cancel = True
.Caption = "Cancel"
End With

End Sub


"Patrick C. Simonds" wrote:

Have a UserForm with a number of TextBoxes. When I click on TextBox1 it
opens a new Userform which displays a ListBox What I need to know is when
I
close the ListBox Userform, how do I get the selected values (which are
in
Column 1,5 and 6) into TextBox 1, 2 and 3.


--

Dave Peterson



Dave Peterson

List Values to TextBox
 
In the textboxes?

if isnumeric(.list(.listindex,0) then
UserForm1.TextBox1.Value = format(.List(.ListIndex, 0), "00:00")
end if

(or "hh:mm" or "mm:ss"????)



"Patrick C. Simonds" wrote:

Thank you,

Any way those ListValues could be formated as 00:00?

"Dave Peterson" wrote in message
...
I used this code to show the second userform2:

Me.Hide
UserForm2.Show
Me.Show

Then I used this code behind UserForm2:

Option Explicit
Private Sub CommandButton1_Click()
With Me.ListBox1
If .ListIndex < 0 Then
'nothing selected, same as cancel?
Else
UserForm1.TextBox1.Value = .List(.ListIndex, 0)
UserForm1.TextBox2.Value = .List(.ListIndex, 1)
UserForm1.TextBox3.Value = .List(.ListIndex, 2)
End If
End With
Unload Me
End Sub
Private Sub CommandButton2_Click()
Unload Me
End Sub
Private Sub UserForm_Initialize()
Dim myRng As Range

With Worksheets("sheet1")
Set myRng = .Range("a1:G5")
End With

With Me.ListBox1
.List = myRng.Value
.ColumnCount = myRng.Columns.Count
.MultiSelect = fmMultiSelectSingle
End With

With Me.CommandButton1
.Default = True
.Caption = "Ok"
End With

With Me.CommandButton2
.Cancel = True
.Caption = "Cancel"
End With

End Sub


"Patrick C. Simonds" wrote:

Have a UserForm with a number of TextBoxes. When I click on TextBox1 it
opens a new Userform which displays a ListBox What I need to know is when
I
close the ListBox Userform, how do I get the selected values (which are
in
Column 1,5 and 6) into TextBox 1, 2 and 3.


--

Dave Peterson


--

Dave Peterson


All times are GMT +1. The time now is 08:35 AM.

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