简体   繁体   中英

Wildcard vlookup in arrays - VBA

I have a problem to vlookup values from one array into another.

Arrays are:

在此处输入图片说明


在此处输入图片说明

My code results in Error 2042:

Dim arr9 As Variant
ReDim arr9(LBound(arr7) + UBound(arr7))
i = 0
For i = LBound(arr7) To UBound(arr7) Step 1
arr9(i) = Application.VLookup(Left(arr7(i), 5) & "*", Arr, 1, 0)
Next i

在此处输入图片说明

What I need is to find items from arr7, ie arr7(0) = zch20 in Arr and assign corresponding value from arr to arr9. Just first 5 characters need to be vlookuped since they are mutual characters for both arr and arr7 but full name string needs to be inserted to arr9.

Thank you.

VLOOKUP is a worksheet function, for use with ranges of cells (or worksheet tables ) but not for VBA arrays .

A comparable VBA function that you might have more luck with is Filter .

Filter(sourcearray, match, [ include, [ compare ]])


More info:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM