Stuck on VLOOKUP VBA using variables
I've been struggling with this one for a few days now:
Trying to have vlookup in code search within a range, see below, I have first row cell and last row cell reference, however; those values are not working in vlookup for some reason.
'Obtain First cell
ActiveSheet.Cells(3, 3).Select
MyFirstRow = ActiveCell.Address
'Obtain Last Cell
ActiveSheet.Cells(3, 3).Select
Selection.End(xlDown).Select
MyLastRow = ActiveCell.Address
Selection.End(xlUp).Select
'Populate cell references
ActiveSheet.Cells(5, 8).Value = MyFirstRow
ActiveSheet.Cells(6, 8).Value = MyLastRow
ActiveSheet.Cells(3, 2).Select
ActiveCell.Formula = "=VLOOKUP($A1,MyFirstRow:MyLastRow,2,FALSE)"
My goal is the following:
LIST OF VALUES TO SEARCH:
ABC
DAA
FEE
FDC
EEE
RANGE:
ADK 1
DAL 2
ETT 5
ABC 3
Search all values within the range, I have a loop and works fine, just need to figure out how to reference vlookup using variables. Appreciate any help I can get, thanks.
I think can only be vlookup though
Thanks so much for helping me. However, I don't know before hand what the values are and could be over 1500 rows in Excel. I have the first and last row cell reference, I need a vlookup to search based on first and last row. Reason for this is that each time program runs the number of rows change, thus I capture first and last and store in variables
'Obtain First cell
ActiveSheet.Cells(3, 3).Select
MyFirstRow = ActiveCell.Address
'Obtain Last Cell
ActiveSheet.Cells(3, 3).Select
Selection.End(xlDown).Select
MyLastRow = ActiveCell.Address
Selection.End(xlUp).Select
'Populate cell references
ActiveSheet.Cells(5, 8).Value = MyFirstRow
ActiveSheet.Cells(6, 8).Value = MyLastRow
ActiveSheet.Cells(3, 2).Select
ActiveCell.Formula = "=VLOOKUP($A$3,MyFirstRow:MyLastRow,2,FALSE)"