Lookup value in array

tiredofit

Well-known Member
Joined
Apr 11, 2013
Messages
1,832
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I have a table consisting of 2 columns, Date and Price.

This table is called MyTable.

For a given date, I want to perform a vlookup.

Code:
Dim TableArray() As Variant

TableArray = Range("MyTable")

In a class I have:

Code:
Private mintPrice As Single

Public Property Get Price() As Single

Price = Application.Vlookup(msngPrice, TableArray ,2, False)

How can I make this work?

Thanks
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
I think you'd have to do something in your code to declare a storage area for the variant array so the value/range/array persists as the declared variable after it is first loaded...

Something like this:

Code:
Public TableArray() As Variant

Sub InitVariant()
    TableArray = Range("MyTable")
End Sub

Sub MyLookupSub()
    MsgBox Application.VLookup(7, TableArray, 2, False)
End Sub

Whether you declare it Public (for usage in all other modules and classes) or Private (for use within the module/class alone) is a programming structure decision you can reason out and adjust for accordingly...
 
Upvote 0

Forum statistics

Threads
1,214,667
Messages
6,120,815
Members
448,990
Latest member
rohitsomani

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
Back
Top