ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Find a string in a range and return two values based on offsets (https://www.excelbanter.com/excel-programming/375021-find-string-range-return-two-values-based-offsets.html)

Aaron Dyck

Find a string in a range and return two values based on offsets
 
I am looking to do something along the lines of a vlookup for a program I am
writing. I am looking in a specific range ("A2:S21") for a value that is
contained in a label. I would like to do a vlookup for this, but I am having
trouble getting it to work. It has to be an exact match for the value in
column A with the caption of my label, and return the Integer values in
columns R and S from the same row. Any suggestions?

Tom Ogilvy

Find a string in a range and return two values based on offsets
 
Dim res as Variant
Dim i1 as Integer, i2 as Integer
res = Application.Vlookup(myVal, Range("A2:S21"),18,0)
if not iserror(res) then
i1 = res
i2 = Application.Vlookup(myVal,Range("A2,S21"),19,0)
else
msgbox "Not found"
End if


another
Dim rng as Range, res as Variant
Dim i1 as Integer, i2 as Integer
set rng = Range("A2:A21")
res = Application.Match(myVal,rng,0)
if not iserror(res) then
i1 = rng(res).offset(0,17).Value
i2 = rng(res).offset(0,18).Value
Else
msgbox "Not found"
End if

--
Regards,
Tom Ogilvy


"Aaron Dyck" wrote in message
...
I am looking to do something along the lines of a vlookup for a program I
am
writing. I am looking in a specific range ("A2:S21") for a value that is
contained in a label. I would like to do a vlookup for this, but I am
having
trouble getting it to work. It has to be an exact match for the value in
column A with the caption of my label, and return the Integer values in
columns R and S from the same row. Any suggestions?





All times are GMT +1. The time now is 12:04 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com