Vbscript Lookup and Return
Posted on 2017-10-12
The below vbscript is a basic script I found on the web. I would like to use it to look up the entered value in a file or ideally a database and return adjacent value. See notes below. It works as is by entering literal values. I'm ok with just a file lookup, but if can do with SQL database too I'd love to see both ways. Thanks!
' Input Box with a Title
a=InputBox("Enter a Number","Enter Value")
‘User enters a value
If a = "1" Then
‘Value goes in Field2
field2 = a
‘ want this value to lookup field2 value (a) in a spreadsheet or text file and return value from adjacent column ‘and place in field3
field3 = "One"
msgbox "Enter a value for Field3"
Example spreadsheet (if user enters “1”, return “One”):
Value One Value Two
Example text file (if user enters “1”, return “One”):