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
Re: userform - combobox & texbox
Quote:
something like this
Code:
for i = 1 to 15
with userform.controls("Combobox" & i)
Code:
Private Sub ComboBox1_Change()
.
.
.
.
userform1.textbox1.value=ComboBox1.List(ComboBox1.ListIndex, 3)
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
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
Re: userform - combobox & texbox