Find a value in an array variable (without looping)

GBagley

Board Regular
Joined
Feb 8, 2011
Messages
84
What would be the fastest way to find a value in a (large, ~25,000 member) array variable and return it's position? Lets assume a 1 dimensional array. I would that using loops or worksheetfunctions would be slower than using an inbuilt VBA method like .find -- what's the best way to do this?
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Match is pretty fast

Code:
Sub test()
Dim i, x
x = Array("a", "b", "c", "d", "e", "f")
i = WorksheetFunction.Match("c", x, 0)
MsgBox x(i - 1)
End Sub
 
Upvote 0
I tried Match, but it was slower than I was hoping. I was thinking that storing data in an array variable and then searching it from within the code (using Match) would be faster than having the code reference back and forth searching between the different worksheets (using .find or vlookup), but it was quite a bit slower.

I ended up getting a significant speed increase by using a couple large, autofilled down, array formulas (which calculate much faster than I would have expected!) to initially consolidate all the raw data that the code needed to reference into a single worksheet. Increased the speed of my macro about 10x :biggrin:
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,738
Members
452,940
Latest member
Lawrenceiow

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