-
May 22nd, 2015, 03:58 AM
#1
Thread Starter
New Member
userform - combobox & texbox
hi
I have a problem and I don't know how to solve it.
I have a userform with 15 comboboxes and 15 textboxes.
combobox1 refer to textbox1, the combobox2 refer to textbox2 etc.
i.e
sub load_data_to_combobox()
.
.
.
With UserForm1.ComboBox1
.ColumnCount = 4
.ColumnWidths = "0;1in;1in;;;"
.TextColumn = 4 'the first column is the ID, the second is the name the third is the price
.AddItem Sheets("sh1").Range("a2:d" & y).Cells(i - 1, 1).Value
End With
.
.
.
end sub
Private Sub ComboBox1_Change()
.
.
.
.
userform1.textbox1.value=???
.
.
.
.
end sub
question1: Is it possible to take the value from the third column of the combobox directly to textbox? I'm using the vlookup from the sheet that contains the data.
question2: The same function load_data_to_combobox I have to repeat for all 15 comboboxes. Is any possibility to use the function "for .. to... next" or "loop" or anything else
something like this
for i =1 to 15
With UserForm1.ComboBox & i ' I tried this but is not working
.ColumnCount = 4
.ColumnWidths = "0;1in;1in;;;"
.TextColumn = 4 'the first column is the ID, the second is the name the third is the price
.AddItem Sheets("sh1").Range("a2:d" & y).Cells(i - 1, 1).Value
End With
next i
thanks for your help
-
May 22nd, 2015, 04:27 AM
#2
Re: userform - combobox & texbox
Code:
for i = 1 to 15
with userform.controls("Combobox" & i)
Code:
Private Sub ComboBox1_Change()
.
.
.
.
userform1.textbox1.value=ComboBox1.List(ComboBox1.ListIndex, 3)
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
May 22nd, 2015, 06:13 AM
#3
Thread Starter
New Member
Re: userform - combobox & texbox
thanks for the reply. It works!!!!!!!!!
I have another question.
Now my combobox sort the items by the first column, the ID.
Is it possible to sort by second column, the name?
again thanks
-
May 22nd, 2015, 06:33 AM
#4
Re: userform - combobox & texbox
i think you would need to sort the items prior to adding ie. sort the input range, else put all the items into an array then sort the array, then add to combobox
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
May 22nd, 2015, 06:49 AM
#5
Thread Starter
New Member
Re: userform - combobox & texbox
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|