?
Solved

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

Posted on 2011-03-22
4
Medium Priority
?
434 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

765 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