VBA Vlookup with Dynamic Data Table Range

BYUIStudent

New Member
Joined
Jun 25, 2015
Messages
10
Hello all. First off thank you so much for all your help. Mr. Excel and your forums has helped me out so much. I am still in the very beginnings of understanding VBA so please forgive my ignorance on certain topics.


This is what I am trying to do.

I am trying to set a cell to =Vlookup($C20,Dynamic table aray,2)

The table array will always be different

This is what i am trying to use

Function VLookUP()
Dim StockTableRange As Range


Sheets("Stock Names").Select
Range("Home").Offset(1, -1).Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Set StockTableRange = Selection


Sheets("Raw Data").Select


Range("RawDate").Offset(1, 1).Select
activecell = "=vlookup($c20,StockTableRange,2)"




End Function


Thank you for your time and your efforts

BYUIstudent.
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

MUKESHY12390

Well-known Member
Joined
Sep 18, 2012
Messages
899
Office Version
  1. 2013
  2. 2011
  3. 2010
  4. 2007
Platform
  1. Windows
Note ---always try to avoid select thing

Code:
Sub D_vlookup()
Dim lr, cl2, Cl As Long
Dim myrnage As Range


lr = Range("Home").Row + 1
cl2 = Range("Home").Column
Cl = Range("Home").End(xlToRight).Column - 1




 Set myrange = Range(Cells(lr, cl2 - 1), Cells(Rows.Count, Cl))


lookup_result = WorksheetFunction.VLookup("search type here", myrange, 2, 0)


End Sub
 

BYUIStudent

New Member
Joined
Jun 25, 2015
Messages
10
Thank you so much for your help.

Regarding your Note. Why do you suggest avoiding "Select Thing"
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,167,992
Messages
5,856,692
Members
431,828
Latest member
kARTIK12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top