Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Selected ListBox item to TextBox
Hi there dear reader...
Usually I find all responses to my Excel issues in already existing threads. Today not. So any help will be more than welcome. The situation is as follows. I have one UserForm with one multiple-column ListBox in it. I would like to add the value of the third column of the selected item of the ListBox to a TextBox located in another userform. The below code does not work : Private Sub ListBox1_DblClick(ByVal cancel As MSForms.ReturnBoolean) For i = 0 To UserForm1.ListBox1.ListCount - 1 If UserForm1.ListBox1.Selected(i) = True Then UserForm1.ListBox1.List(i, 12).AddItem UserForm2.TextBox1.Text Next i UserForm2.Show End Sub Thank you in advance for your help Honnore |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Selected ListBox item to TextBox
Try this DblClick event code instead of what you posted...
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean) UserForm2.TextBox1 = ListBox1.List(ListBox1.ListIndex, 2) End Sub -- Rick (MVP - Excel) "Honnore" <u51305@uwe wrote in message news:94e04f7c72662@uwe... Hi there dear reader... Usually I find all responses to my Excel issues in already existing threads. Today not. So any help will be more than welcome. The situation is as follows. I have one UserForm with one multiple-column ListBox in it. I would like to add the value of the third column of the selected item of the ListBox to a TextBox located in another userform. The below code does not work : Private Sub ListBox1_DblClick(ByVal cancel As MSForms.ReturnBoolean) For i = 0 To UserForm1.ListBox1.ListCount - 1 If UserForm1.ListBox1.Selected(i) = True Then UserForm1.ListBox1.List(i, 12).AddItem UserForm2.TextBox1.Text Next i UserForm2.Show End Sub Thank you in advance for your help Honnore |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Selected ListBox item to TextBox
Hi Rick...
First of all, thanks for this fast reply. I changed my code to the following and it wotks partially: UserForm2.TextBox1.Value = UserForm1.ListBox1.List(i, 9) I say partially because if I want to add in the TextBox a value that is above the 9th column of the selected item in the ListBox, it doesn't work anymore. Strange. If you or someone else has an idea it would be more than welcome Rick Rothstein wrote: Try this DblClick event code instead of what you posted... Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean) UserForm2.TextBox1 = ListBox1.List(ListBox1.ListIndex, 2) End Sub Hi there dear reader... Usually I find all responses to my Excel issues in already existing [quoted text clipped - 18 lines] Thank you in advance for your help Honnore |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Selected ListBox item to TextBox
What do you mean by "a value that is above the 9th column"? And what is the
"i" variable for? The code I posted was meant to replace all of your code (notice I posted the event header and the End Sub statements with my single line of code)... it was not meant to be merged with the code you posted. Because you are using the DblClick event, the selected row will be the row that the user double clicks on... the ListIndex that I used as an argument for the List property returns that row number directly (where the first row is numbered 0)... no loop is necessary to find it. Again, the code you will actually need will depend on the first question I asked you above (and on what "above" means in it). -- Rick (MVP - Excel) "Honnore" <u51305@uwe wrote in message news:94e0ba9986331@uwe... Hi Rick... First of all, thanks for this fast reply. I changed my code to the following and it wotks partially: UserForm2.TextBox1.Value = UserForm1.ListBox1.List(i, 9) I say partially because if I want to add in the TextBox a value that is above the 9th column of the selected item in the ListBox, it doesn't work anymore. Strange. If you or someone else has an idea it would be more than welcome Rick Rothstein wrote: Try this DblClick event code instead of what you posted... Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean) UserForm2.TextBox1 = ListBox1.List(ListBox1.ListIndex, 2) End Sub Hi there dear reader... Usually I find all responses to my Excel issues in already existing [quoted text clipped - 18 lines] Thank you in advance for your help Honnore |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Selected ListBox item to TextBox
Let me put it in another way...
I have a ListBox which I populate with the additem "method". The ListBox has 14 column. I would like to extract the value of each column of the selected item into TextBoxes that are in an other Useform... The here below code you gave me works fine until the 9th column: Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean) UserForm2.TextBox1 = ListBox1.List(ListBox1.ListIndex, 9) End Sub When willing to retreive the value of the 10th column and above it doesn't work anymore. In clear words, the here below code doesn't work Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean) UserForm2.TextBox1 = ListBox1.List(ListBox1.ListIndex, 10) End Sub Rick Rothstein wrote: What do you mean by "a value that is above the 9th column"? And what is the "i" variable for? The code I posted was meant to replace all of your code (notice I posted the event header and the End Sub statements with my single line of code)... it was not meant to be merged with the code you posted. Because you are using the DblClick event, the selected row will be the row that the user double clicks on... the ListIndex that I used as an argument for the List property returns that row number directly (where the first row is numbered 0)... no loop is necessary to find it. Again, the code you will actually need will depend on the first question I asked you above (and on what "above" means in it). Hi Rick... First of all, thanks for this fast reply. [quoted text clipped - 20 lines] Thank you in advance for your help Honnore -- Message posted via OfficeKB.com http://www.officekb.com/Uwe/Forums.a...mming/200904/1 |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Selected ListBox item to TextBox
I'm not sure what to tell you... the code works fine on my tests... I can
pull values past column 9 with no trouble using that line of code. Perhaps you have a counter locked at a maximum of 9 somewhere in your code. -- Rick (MVP - Excel) "Honnore via OfficeKB.com" <u51305@uwe wrote in message news:94ec082e7670f@uwe... Let me put it in another way... I have a ListBox which I populate with the additem "method". The ListBox has 14 column. I would like to extract the value of each column of the selected item into TextBoxes that are in an other Useform... The here below code you gave me works fine until the 9th column: Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean) UserForm2.TextBox1 = ListBox1.List(ListBox1.ListIndex, 9) End Sub When willing to retreive the value of the 10th column and above it doesn't work anymore. In clear words, the here below code doesn't work Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean) UserForm2.TextBox1 = ListBox1.List(ListBox1.ListIndex, 10) End Sub Rick Rothstein wrote: What do you mean by "a value that is above the 9th column"? And what is the "i" variable for? The code I posted was meant to replace all of your code (notice I posted the event header and the End Sub statements with my single line of code)... it was not meant to be merged with the code you posted. Because you are using the DblClick event, the selected row will be the row that the user double clicks on... the ListIndex that I used as an argument for the List property returns that row number directly (where the first row is numbered 0)... no loop is necessary to find it. Again, the code you will actually need will depend on the first question I asked you above (and on what "above" means in it). Hi Rick... First of all, thanks for this fast reply. [quoted text clipped - 20 lines] Thank you in advance for your help Honnore -- Message posted via OfficeKB.com http://www.officekb.com/Uwe/Forums.a...mming/200904/1 |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
Selected ListBox item to TextBox
It probably works for you because you have linked your listbox to a row
source. In that case it works. On my side I have used the additem method to populate my listbox. In that case the limited amount of column is 9. Thanks for your help. Ciao Rick Rothstein wrote: I'm not sure what to tell you... the code works fine on my tests... I can pull values past column 9 with no trouble using that line of code. Perhaps you have a counter locked at a maximum of 9 somewhere in your code. Let me put it in another way... I have a ListBox which I populate with the additem "method". The ListBox [quoted text clipped - 35 lines] Thank you in advance for your help Honnore -- Message posted via OfficeKB.com http://www.officekb.com/Uwe/Forums.a...mming/200904/1 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Worksheet Listbox selected item? | Excel Programming | |||
Delete selected Item from listbox | Excel Programming | |||
How to get the index in VBA of the selected item in a ListBox | Excel Programming | |||
Need selected item from listbox after double click | Excel Programming | |||
Count number of selected item in Listbox | Excel Programming |