Retrive Data in Userform [from Shahzad]
Hi Shahzad
One way you could do it would be. Say you have data in sheet1 in a
range A1:C10 you can pass that range to a combobox but only have it
show the first column A1:A10 in the combobox from there you can set
the change event for the combobox to put the related data into your
textboxes using the listindex and columns. Add two textboxes and a
combobox to a userform then paste the following code should give you a
clearer idea of what i'm trying to say.
Option Explicit
Dim i As Integer
Private Sub ComboBox1_Change()
i = ComboBox1.ListIndex 'Pass the current listindex to an Integer
'keep in mind that the columns start from 0
'pass the rest of your columns to the textboxes
TextBox1.Value = ComboBox1.Column(1, i) 'This is column B
TextBox2.Value = ComboBox1.Column(2, i) 'This is column C
End Sub
Private Sub UserForm_Initialize()
ComboBox1.RowSource = "A1:C10" 'Set your range
End Sub
hope this helps
|