[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2011-03-22
4
Medium Priority
?
437 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 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

873 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