+ Reply to Thread
Results 1 to 6 of 6

VLookup - function is not detecting lookup value on dynamic array

  1. #1
    Registered User
    Join Date
    11-22-2016
    Location
    London
    MS-Off Ver
    2013
    Posts
    23

    VLookup - function is not detecting lookup value on dynamic array

    I want to apply the Vlookup function on a column, being the table_array from another sheet in my workbook which is dynamic.

    My code works but it's not giving back any values.

    Consider only the part in bold of the code:

    Private Sub CommandButton3_Click()

    Dim src As Worksheet
    Dim tgt As Worksheet
    Dim com As Worksheet
    Dim filterRange As Range
    Dim copyRange As Range
    Dim copyRange2 As Range
    Dim copyRange3 As Range
    Dim calcRange As Range

    Dim Lastrow As Long


    Set src = ThisWorkbook.Sheets("Importação")
    Set tgt = ThisWorkbook.Sheets("Status")
    Set com = ThisWorkbook.Sheets("Ficheiro Endesa")


    src.AutoFilterMode = False


    Lastrow = src.Range("B" & src.Rows.Count).End(xlUp).row


    Set filterRange = src.Range("B9:N" & Lastrow)

    Set copyRange = src.Range("B10:C" & Lastrow)

    Set copyRange2 = src.Range("G10:G" & Lastrow)

    Set copyRange3 = src.Range("K10:K" & Lastrow)


    filterRange.AutoFilter Field:=5, Criteria1:="="


    copyRange.SpecialCells(xlCellTypeVisible).Copy
    tgt.Range("B21").PasteSpecial xlPasteValues


    copyRange2.SpecialCells(xlCellTypeVisible).Copy
    tgt.Range("D21").PasteSpecial xlPasteValues


    copyRange3.SpecialCells(xlCellTypeVisible).Copy
    tgt.Range("E21").PasteSpecial xlPasteValues



    filterRange.AutoFilter Field:=5




    Lastrow = com.Range("B" & com.Rows.Count).End(xlUp).row


    Set calcRange = com.Range("D8:G" & Lastrow)


    Range("G21").Select
    ActiveCell.FormulaR1C1 = _
    "=+IFERROR(VLOOKUP(RC[-5],calcRange,3,FALSE),""-"")"

    Range("G21").Select
    Range("G21").AutoFill Destination:=Range("G21:G" & Cells(Rows.Count, "B").End(xlUp).row)


    End Sub

  2. #2
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: VLookup - function is not detecting lookup value on dynamic array

    Hi,

    calcRange is a VBA variable and not a named range. It will therefore not work in a formula. You might use
    Please Login or Register  to view this content.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  3. #3
    Registered User
    Join Date
    11-22-2016
    Location
    London
    MS-Off Ver
    2013
    Posts
    23

    Re: VLookup - function is not detecting lookup value on dynamic array

    Thanks for the reply.

    I tried but it gives back an error: Run-Time error '1004': Application-defined or object-defined error

    Do i need to adapt something from your code to my specific case?

  4. #4
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: VLookup - function is not detecting lookup value on dynamic array

    Please use code tags when posting code...
    That said, try replacing
    Please Login or Register  to view this content.
    with
    Please Login or Register  to view this content.
    xlnitwit had it solved, the only issue was the missing (ReferenceStyle:=xlR1C1) because the formulaR1C1 requires that type of reference for the address of calcRange.
    Last edited by Arkadi; 11-29-2016 at 10:12 AM.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  5. #5
    Registered User
    Join Date
    11-22-2016
    Location
    London
    MS-Off Ver
    2013
    Posts
    23

    Re: VLookup - function is not detecting lookup value on dynamic array

    It's already working properly!

    Thank you very much xlnitwit and Arkadi.

  6. #6
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: VLookup - function is not detecting lookup value on dynamic array

    Glad we could help you fix it
    Please remember to mark the thread as solved? Thanks!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Dynamic Row Lookup Array within Array formula
    By OLLY-7 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 07-17-2014, 04:55 PM
  2. Dynamic or Variable Lookup array in INDEX, MATCH or VLOOKUP
    By kishor_c in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-16-2012, 09:46 AM
  3. Need Help With Dynamic VLOOKUP Target Array
    By rattler0812 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-18-2011, 10:53 PM
  4. Replies: 2
    Last Post: 11-05-2011, 03:26 PM
  5. array dynamic vlookup
    By gakuto in forum Excel General
    Replies: 12
    Last Post: 08-09-2011, 07:29 AM
  6. Dynamic Array lookup
    By lopg2009 in forum Excel General
    Replies: 12
    Last Post: 09-18-2010, 01:41 PM
  7. Using Vlookup to lookup array, return array
    By jcampbell in forum Excel General
    Replies: 5
    Last Post: 11-16-2007, 01:13 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1