easy search automatically display like a Vlookup but in VBA

Patriot2879

Well-known Member
Joined
Feb 1, 2018
Messages
1,259
Office Version
  1. 2010
Platform
  1. Windows
Hi I have the code below but i want to change cell A2 to a 'TextBox1' as now instead of using cells and vlookup i want to put this into a userform instead, so in textbox1 i will enter the data to search then in textbox3 and textbox4 it will display automatically the results, can you help please, i am new to this still :)
Code:
result = [VLOOKUP(Sheet2!A2, Data!A:AA, 3, FALSE)]
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Try using this:

Code:
Private Sub TextBox1_Change()

TextBox2.Text = ""
myRow = Application.Match(TextBox1.Text, Sheets("Data").Columns("A"), 0)
If Not IsError(myRow) Then
    TextBox2.Text = Sheets("Data").Range("C" & myRow).Value
End If

End Sub
 
Upvote 0
hi thanks for this but it didnt work, the textbox is in a userform7 does that needs mentioning in the code?
 
Upvote 0
It needs adding to that userforms module thats all. Didnt work isnt entirely helpful. In what way? What did/ didnt happen? What is the data? Text, number, date?
 
Upvote 0
sorry, for example i type in the data i am looking form into textbox1 and it didnt load up the info found in sheet1 to load up in textbox2, the textbox are built in userform7 hope that helps? sorry not being very informative and basic i am new to this :)
 
Upvote 0
No its trying to find the data in column A of sheet called Data because that what the vlookup was doing. Where have you put the code by the way? When you go into the VBA window you right click the userform in question, view code and then paste it there.
 
Upvote 0
Sorry this was the code i was using below as a vlookup which worked, but now i have made a userform7 and i want this to do the same thing, i type the number in textbox1 and it will automatically find the details in sheet1 and input into textbox2, sorry for the mistake previously
Code:
=VLOOKUP(Northants!$J$16, Sheet1!$A:$AA,26,FALSE)
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top