fetch a value from a w/sheet to userform.

  • Thread starter tkraju via OfficeKB.com
  • Start date
T

tkraju via OfficeKB.com

I have a userform with a combobox 1,a text box 1and a command button(fetch)
I want sheet1! A2 to last used cell in Col A as combobox 1 values.
If a a value is selected from combox list ,and click fetch command button,
then > vlookup that value from sheet1A2:F200,from column 5 fetch to textbox1.
what code I have to add to userform code module for above 2 tasks.
Thanks in advance to all Vba experts.
 
S

slarbie

with just your combobox you could accomplish what you're describing. Set the
combobox columncount property to 2, then use the following code for the form.
Vlookup isn't needed at all this way. The combobox shows what's in the
second column, and can return that value anywhere you want to use it. But if
you absolutely had to have it in a textbox for some reason, this shows that
as well. You really don't need the "fetch" button.

Private Sub UserForm_Initialize()

Dim myList As String
Dim LastRow As Integer

LastRow = Range("a2").End(xlDown).Row
myList = Range(Cells(2, 1), Cells(LastRow, 2)).address
ComboBox1.RowSource = myList

End Sub

Private Sub ComboBox1_Change()

TextBox1 = ComboBox1.Column(1)

End Sub
 
T

tkraju via OfficeKB.com

Thank you ,Slarbie,I got what I need, can you explain me the code,line by
line.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top