Use VLOOKUP to populate text box on form
Try this
Private Sub UserForm_Initialize()
With Worksheets("Data")
Me.cboFuel1.List = .Range("A18", _
.Cells(.Rows.Count, "A").End(xlUp)).Value
End With
End Sub
Private Sub cboFuel1_Change()
With Worksheets("Data")
Lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
Set DataRange = .Range("A18", "A" & Lastrow)
SelectedItem = Me.cboFuel1.Value
Set c = DataRange.Find(what:=SelectedItem, _
LookIn:=xlValues, lookat:=xlWhole)
If Not c Is Nothing Then
TextBoxdata = c.Offset(0, 1)
End If
End With
End Sub
"Greg Snidow" wrote:
Greetings everyone. I'm not sure if I can do this, but on a user form I have
a combo box that populates from a range on sheet 'DATA', with items. There
is also a text box that I want to find the price of that item. Thoretically,
assuming my data is such that item is in column A of 'DATA', starting at row
18, and price is in column B of 'DATA', how can I get the price of the item
selected from the combo box. I found a post by Dave Peterson to populate the
list of the combo, but I am at a loss as to how to populate the text box for
price. Any ideas? Below is the code to populate the list(thanks Dave).
Private Sub UserForm_Initialize()
With Worksheets("Data")
Me.cboFuel1.List = .Range("A18", .Cells(.Rows.Count,
"A").End(xlUp)).Value
End With
Greg
|