PDA

View Full Version : [SOLVED] vlookup array values



cruzrji1
04-22-2016, 02:52 PM
I´ve been struggling witht this for a while, please help...

I want to store range("F1:F3") as arr1, then store range ("A1:C100") as arr2, also have a third array called arr3, then I need to vlookup all the values for arr1 in arr2 and store the results in arr3, then write arr3 in range("H1:H3"). I need to do this in VBA and store the results as variables in another array, because I will perform more calculations based on the result of the vlookup, also this is as a test, actual values to vlookup and return results are about 4,000

so far...


sub looking()
dim arr1() as variant
dim arr2() as variant
dim arr3(1,3) as variant
arr1= range("F1:F3").value
arr2= range("A1:C100").value
for i=1 to 3
arr3(i,1)=worksheetfunction.vlookup(arr1(i,1),arr2,2,false)
next i
range("H1:H3").value=arr3
end sub


What is wrong with this?!

cruzrji1
04-22-2016, 03:16 PM
I already did it! all by my self xD I think actually asking the question help to think better, This worked for me:


Sub looking2()
Dim arr1() As Variant
Dim arr2() As Variant
Dim arr3(3, 1) As Variant
arr1 = Range("F1:F3").Value
arr2 = Range("A1:C500").Value
For i = 1 To 3
arr3(i, 1) = WorksheetFunction.VLookup(arr1(i, 1), arr2, 2, False)
Range("H" & i).Value = arr3(i, 1)
Next i
End Sub

Of course this was a test for looping vlookup values, the final macro Im working ok is more extensive so I will be posting questions in the future =)

Paul_Hossler
04-23-2016, 04:17 PM
I already did it! all by my self xD I think actually asking the question help to think better,


Best way to learn. :thumbMany times I've figured out something by trying to explain the problem to some one




the final macro Im working ok is more extensive so I will be posting questions in the future


See you then :hi:

PS - you can mark it [Solved] by using [Thread Tools] in the menu bar for your first post