Solved

Find data in a Excel spreadsheet and display it in a userform

Posted on 2011-03-22
4
415 Views
Last Modified: 2012-05-11
Hi,

I have a spreadsheet containing a lot of data. I would like to search a column (column A) for a number entered in an userform and return the value in the corresponding cell next to it (column B) to a textbox in the userform.

How do I do that?
0
Comment
Question by:Christian_G
  • 2
  • 2
4 Comments
 
LVL 6

Expert Comment

by:FernandoFernandes
ID: 35189953
let's suppose that the textbox where the value will be entered is textbox1 and the result will be displayed is called textbox2.
dim result as variant
dim lookupvalue as variant

lookupvalue = textbox1.text
result = application.worksheetfunction.vlookup(lookupvalue,range("A:B"),2,0)

textbox2.text = result

Open in new window

0
 

Author Comment

by:Christian_G
ID: 35196426
I changed the lookupvalue data type to Double as all data is decimal numbers.
But what if I also would like to return values from column D and G?
0
 
LVL 6

Accepted Solution

by:
FernandoFernandes earned 500 total points
ID: 35198392
then you'll have to
1) declare new variables to populate those results
2) determine to which textbox'es those results will be win
3) adapt the vlookup's parameters to the new realities, for instance:

result1 = application.worksheetfunction.vlookup(lookupvalue,range("A:B"),2,0)
result2 = application.worksheetfunction.vlookup(lookupvalue,range("A:D"),4,0)
result3 = application.worksheetfunction.vlookup(lookupvalue,range("A:G"),7,0)

textbox2.text = result1
textbox3.text = result1
textbox4.text = result1


if you're good at working with vlookup inside Excel, you'll see that from within the code it's pretty much the same thing :-)

p.s.: the names I used are examples, in your code you'll probably have to adapt it...
0
 

Author Closing Comment

by:Christian_G
ID: 35200258
Thanks!
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now