Consulting

Results 1 to 3 of 3

Thread: vlookup array values

  1. #1
    VBAX Newbie
    Joined
    Apr 2016
    Posts
    2
    Location

    vlookup array values

    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?!
    Last edited by Aussiebear; 04-22-2016 at 05:09 PM. Reason: added hash tag to code

  2. #2
    VBAX Newbie
    Joined
    Apr 2016
    Posts
    2
    Location
    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 =)
    Last edited by Aussiebear; 04-22-2016 at 05:13 PM. Reason: Added hash tag to code

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    I already did it! all by my self xD I think actually asking the question help to think better,
    Best way to learn. Many 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

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

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •