Results 1 to 9 of 9

Xlookup returns "-" but not the return array's value

Threaded View

  1. #1
    Forum Contributor
    Join Date
    06-20-2021
    Location
    UK
    MS-Off Ver
    2016
    Posts
    126

    Unhappy Xlookup returns "-" but not the return array's value

    Definitions of variables:

    Book1 (main file where we will store output values from xlookup): Cell "A3" = LookUpVal
    Book 2 (source data): Col G = RetArr; Col A = SrcArr


    Problem 1:

    Without using address property with search and return arrays, in the arguments of Xlookup, it doesn't even work (Error: unable to get Xlookup property of worksheet function class).

    Problem 2:

    The return value in book 1 is empty i.e. "-" as supplied in xlookup argument.

    What I have tried:


    1. Without address and with address in Xlookup

    2. Checked values in srcArr, LookupVal and retArr to be correct. This was check through srcArr.select as well as looping through debug.print cells value. So I know it is selecting the right ranges, and values.

    3. Checked workbook values, and they are correct alongside sheet names.



    Sub XlookMultipleWorkbooks()
    
    Dim lookupVal As Range, srcArr As Range, retArr As Range
    Dim Book1 As Workbook, Book2 As Workbook
    Dim Book1Rows As Long, Book2Rows As Long
    
    Application.ScreenUpdating = False
    
    With Application.FileDialog(msoFileDialogFilePicker)
        .ButtonName = "Select One File"
        If .Show = -1 Then
            f = .SelectedItems(1)
        End If
    End With
    
    'Set some Workbook variables:
    
    Set Book1 = ThisWorkbook 'CHANGE THIS
    Set Book2 = Workbooks.Open(f)
    
    'Count rows on both workbooks
    
    Book1Rows = Book1.ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
    Book2Rows = Book2.ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
    
    'Set range to set for lookup range (note this is only for column G now!)
    
    Set lookupVal = Book1.Sheets("Test").Cells(3, 1)
    
    With Book2.ActiveSheet
        Set srcArr = .Range(Cells(3, 1), Cells(Book2Rows, 1))
        Set retArr = .Range(Cells(1, 7), Cells(Book2Rows, 7))
    End With
    
    Book1.Sheets("Test").Cells(3, 2).Value = Application.WorksheetFunction.XLookup _
    (lookupVal, srcArr.Address, retArr.Address, "-") 'This only returns "-" in Cells(3,2)? It should return 564 quantity.
    End Sub
    If I can past the hurdle of actually getting return values from the search array, then I will be on my way to loop through each lookup value and put it inside test worksheet.

    Due to company policy any workbook upload is blocked but I want Xlookup to read from yellow columns essentially. I am testing this code on cols A and G only.


    XlookUpToSave.png

    ReturnArray.png
    Last edited by immigrated4urjob; 09-16-2021 at 08:59 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] XLookup reusing "old" return value
    By norgaards in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 02-17-2021, 10:28 AM
  2. Replies: 4
    Last Post: 07-10-2014, 08:10 PM
  3. CHOOSE Function returns "#VALUE!" when using an array
    By wolf83 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-25-2013, 09:37 PM
  4. Replies: 2
    Last Post: 10-24-2011, 05:30 AM
  5. Replies: 3
    Last Post: 02-16-2011, 02:55 PM
  6. Formula returns "0"; How do I make it return nothing?
    By jonlandrum in forum Excel General
    Replies: 5
    Last Post: 04-18-2006, 07:40 PM
  7. [SOLVED] If changed array formula reduce ""\""\""\ - signs to #Missing, will it make ...
    By Maria J-son in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-05-2006, 08:25 AM

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