VBA Question: how perform a "match" in a VBA array

strattergize

New Member
Joined
Nov 24, 2007
Messages
12
If I have a 2 dimensional VB array, can I perform the equivalent of a vlookup on it? The following code didn't work:

x = WorksheetFunction.VLookup("271", MasterArray, 2, 0)

Or if it is simpler, what code could determine where a given value is in a one-dimensional array? In Excel I would simply use the MATCH function and it would return what position the given value is. If I could know the position then I could just use code like this to retrieve the ultimate value:

x = MasterArray(determined_position_of_value, 2)

Any help would be greatly appreciated! Thanks in advance.

JaredSorensen
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
here is one way
Cells.Find(What:=UserForm1.txtPT, After:=ActiveCell, LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate ' this looks in userform1.txtpt if match is found this is tells userform1.txtpt = activecell that it found

UserForm1.txtPT = ActiveCell 'cell it finds
 
Upvote 0
Hi Jared & Welcome to the Board!

You can use Match on a an array that only has the one dimension therefore the following will determine the position in the array of the sought for string:

Code:
Dim vArr as Variant
vArr = Range("A1:A10").Value 'fill variant array with cell values in A1:A10

Msgbox Application.WorksheetFunction.Match("SomeValue",vArr,0)  'this will return the position of "SomeValue" within vArr or an error if it fails to find it

With a two dimensional array you can use Vlookup eg:

Code:
Dim vArr2 as Variant
vArr2 = Range("A1:B10").Value 

Msgbox Application.WorksheetFunction.Vlookup("SomeValue",vArr2,2,0)

Make sense?
 
Upvote 0
hi,

I want a formula which would do the following:
Matching the date (column B) with that in row H2 onwards, and then it will match the names written in column C with names in column H
and after matching these conditions, the hyperlink will connect to name in column H

please help!!!!
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,315
Members
452,634
Latest member
cpostell

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