Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 153
Default Use VLOOKUP to populate text box on form

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default 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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Use VLOOKUP to populate text box on form

Try the below which is the combo change event...which will lookup the
corresponding value in ColB and populate that to me.textbox1

Private Sub cboFuel1_Change()
Me.TextBox1 = WorksheetFunction.VLookup(Me.ComboBox1, _
Worksheets("Data").Range("A:B"), 2, 0)
End Sub


If this post helps click Yes
---------------
Jacob Skaria


"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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Use VLOOKUP to populate text box on form

Typo...
comboname is cboFuel1
textbox name is TextBox1

Private Sub cboFuel1_Change()
Me.TextBox1 = WorksheetFunction.VLookup(Me.cboFuel1, _
Worksheets("Data").Range("A:B"), 2, 0)
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"Jacob Skaria" wrote:

Try the below which is the combo change event...which will lookup the
corresponding value in ColB and populate that to me.textbox1

Private Sub cboFuel1_Change()
Me.TextBox1 = WorksheetFunction.VLookup(Me.ComboBox1, _
Worksheets("Data").Range("A:B"), 2, 0)
End Sub


If this post helps click Yes
---------------
Jacob Skaria


"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


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 153
Default Use VLOOKUP to populate text box on form

Jacob, I hit the "yes" button, for whether or not this post answered the
question, but for some reason yours is not showing up. I just wanted to let
you know I did not omit your solution. Maybe its a bug?

"Jacob Skaria" wrote:

Typo...
comboname is cboFuel1
textbox name is TextBox1

Private Sub cboFuel1_Change()
Me.TextBox1 = WorksheetFunction.VLookup(Me.cboFuel1, _
Worksheets("Data").Range("A:B"), 2, 0)
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"Jacob Skaria" wrote:

Try the below which is the combo change event...which will lookup the
corresponding value in ColB and populate that to me.textbox1

Private Sub cboFuel1_Change()
Me.TextBox1 = WorksheetFunction.VLookup(Me.ComboBox1, _
Worksheets("Data").Range("A:B"), 2, 0)
End Sub


If this post helps click Yes
---------------
Jacob Skaria


"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




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,942
Default Use VLOOKUP to populate text box on form

hi
add something like this to your combo box change event
Private Sub Cbo1_Change()
Dim cbv As String
Dim r As Range
cbv = Me.Cbo1.Value
Set r = Range("A18:B24")
Me.TextBox1.Value = WorksheetFunction.VLookup(cbv, r, 2)

regards
FSt1
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


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default Use VLOOKUP to populate text box on form

make the combox columncount = 2 and set the BoundColumn =2

set the source to both columns A and B of your data


if you don't want to see the value of B in the combobox, then set its column
width to zero

now, when you click an item (change) the value returned will be the value
thats in the 2nd column


"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


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Use VLOOKUP to populate text box on form

You can create a combobox that has multiple columns (and even hide the second
column from view) and then just get the second column's value from the
combobox--never go back to the worksheet.

Option Explicit
Private Sub ComboBox1_Change()
With Me.ComboBox1
If .ListIndex < 0 Then
'nothing chosen, clear the textbox
Me.TextBox1.Value = ""
Else
Me.TextBox1.Value = .List(.ListIndex, 1)
End If
End With
End Sub
Private Sub UserForm_Initialize()
Dim myRng As Range

With Worksheets("Data")
Set myRng = .Range("A18:B" & .Cells(.Rows.Count, "A").End(xlUp).Row)
End With

With Me.ComboBox1
.ColumnCount = myRng.Columns.Count
.List = myRng.Value
.ColumnWidths = "100;0" 'hide the second column
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


--

Dave Peterson
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 153
Default Use VLOOKUP to populate text box on form

Wow, thank you all so much for the good solutions, all of them work very
well. Coincidentally, I messed around with it last night, and got it to work
in a much less elegant fashion. Below is the code, which will promptly be
deleted. One question I have about my version, is that I could not set the
LstRow variable by any means I found here. I know it is a simple syntax
error.

Dim StartCellAddress As String
Dim CurrentCellString As String
Dim LookupValue As Double
StartCellAddress = Sheets("data").Range("A2").Address
CurrentCellString = Sheets("data").Range(StartCellAddress).Value

Dim LstRow As Integer
'LstRow = Sheets("data").Cells(.Rows.Count, "A").End(xlUp).Row
LstRow = 13
Dim MyCell As String
Dim Rng As Range
Set Rng = Sheets("data").Range("A2:A" & LstRow)

LookupValue = Sheets("data").Range(StartCellAddress).Offset(0, 1).Value
For n = 1 To LstRow
If Me.cboFuel1.Value = CurrentCellString Then
Me.txtPrc1.Value = LookupValue
Exit For
Else
StartCellAddress = Sheets("data").Range("A2").Offset(n, 0).Address
CurrentCellString = Sheets("data").Range(StartCellAddress).Value
LookupValue = Sheets("data").Range(StartCellAddress).Offset(0,
1).Value
End If
Next

"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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to populate web form confused Excel Programming 11 March 26th 11 07:29 PM
Populate form from row data Kent McPherson[_2_] Excel Programming 0 June 19th 09 10:33 PM
how do i use the text in a cell as a named range in a vlookup form SB_2009 Excel Discussion (Misc queries) 2 February 10th 09 02:05 PM
Populate a form Doug Excel Worksheet Functions 3 December 15th 06 03:33 PM
Populate Userform text boxes in VBA with VLookup data from #2 worksheet Laz[_2_] Excel Programming 4 October 8th 03 02:15 AM


All times are GMT +1. The time now is 01:13 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"