Userform Textbox

P

paulwes

Hi
I am trying to get a textbox (textbox2) in a userform to vlookup data
(entered into textbox1) from cells ("a1:b10"). Can anybody please
advise if this can be done and how?
thanks
 
D

Dave Peterson

Dim Res as Variant

res = application.vlookup(me.textbox1.value, _
thisworkbook.worksheets("sheet999").range("a1:B10"),2,false)

if iserror(res) then
me.textbox2.value = "No match, the board goes back"
else
me.textbox2.value = res
end if


====
You may want to change the workbook and the sheetname, though.
 
R

Rick Rothstein \(MVP - VB\)

I am trying to get a textbox (textbox2) in a userform to vlookup data
(entered into textbox1) from cells ("a1:b10"). Can anybody please
advise if this can be done and how?

Maybe you can use the VBA Find function instead. Assuming you are looking up
your values in Column A and returning the corresponding values from Column
B, I would think this code could be used (change the Find properties as
required)...

On Error Resume Next
TextBox2.Text = ActiveSheet.Range("A1:A10").Find( _
What:=TextBox1.Text, MatchCase:=False, _
SearchOrder:=xlByColumns).Offset(0, 1).Value
If Err.Number Then TextBox2.Text = "No Match Found"

Rick
 
G

Guest

Private Sub TextBox1_Change()
On Error Resume Next
Me.TextBox2 = ""
Me.TextBox2 = Range("A1:A10").Find(Me.TextBox1, LookIn:=xlValues).Offset(0, 1)
End Sub


"(e-mail address removed)" skrev:
 

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