Solved

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

Posted on 2011-03-22
4
417 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
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.

786 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