+ Reply to Thread
Results 1 to 6 of 6

VBA Code for XLOOKUP Using Multiple Criteria That Are Dynamic

  1. #1
    Registered User
    Join Date
    10-12-2024
    Location
    This is a site run by a bunch of fascists!
    MS-Off Ver
    Fascist Site!
    Posts
    16

    VBA Code for XLOOKUP Using Multiple Criteria That Are Dynamic

    Hello,

    I need help writing a VBA code for macro that will perform an XLOOKUP formula based on three lookup values from a return array that is a sub-total. Since the return array is a sub-total, I have to perform "Select Visible Cells" to paste the data into a new sheet in order to do my XLOOKUP formula. I would like to know if there's a way to do the XLOOKUP based on the visible cells of the return array, so that I don't have to paste the data into another spreadsheet.

    Also, I would like the macro to only run the XLOOKUP formula if the column header contains a specific name that I designate.

    The original version of the workbook has thousands of rows, so the lookup value combination will change as we go through each row, making it dynamic. Below are print screens of my data with my formula in Excel, as well as the attached sample workbook.

    Many thanks for assisting me with this!
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by hain2004; 10-12-2024 at 11:18 PM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,972

    Re: VBA Code for XLOOKUP Using Multiple Criteria That Are Dynamic

    You don't necessarily need VBA. Try:

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Adjust the NewData ranges as required but avoid full column references.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    10-12-2024
    Location
    This is a site run by a bunch of fascists!
    MS-Off Ver
    Fascist Site!
    Posts
    16

    Re: VBA Code for XLOOKUP Using Multiple Criteria That Are Dynamic

    Hello,

    Thank you for this, but I'm looking to get the XLOOKUP formula into a VBA code that will loop through each row of my data range based on my three lookup values.

  4. #4
    Registered User
    Join Date
    12-30-2020
    Location
    Here
    MS-Off Ver
    M365
    Posts
    63

    Re: VBA Code for XLOOKUP Using Multiple Criteria That Are Dynamic

    Your XLOOKUP is equivalent to this formula, if you remove sutotals from 'NewData' sheet.
    =SUMIFS(NewData!L$2:L$23, NewData!E$2:E$23,B2, NewData!F$2:F$23,E2, NewData!G$2:G$23,I2)
    This formula don't need 'NewData2' sheet.
    so, simply enter this formula or VBA coding like below.
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by mojirhi; 10-13-2024 at 04:33 AM.

  5. #5
    Registered User
    Join Date
    10-12-2024
    Location
    This is a site run by a bunch of fascists!
    MS-Off Ver
    Fascist Site!
    Posts
    16

    Re: VBA Code for XLOOKUP Using Multiple Criteria That Are Dynamic

    Hmmm, what an interesting take! I did not realize that my XLOOKUP formula can be re-written to a SUMIFS formula! This code worked like a charm, so thank you!

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,972

    Re: VBA Code for XLOOKUP Using Multiple Criteria That Are Dynamic

    So, I get negative rep for trying to help you?
    It did not answer my question.
    Well, thanks for that. I won't be rushing to try to help you in the future.

    Didn't your mother teach you: if you can't say something nice, say nothing.

+ 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. [SOLVED] Xlookup with multiple IF Criteria
    By T.Turner in forum Excel General
    Replies: 14
    Last Post: 10-05-2023, 06:49 AM
  2. Xlookup multiple criteria
    By mcis19 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 01-26-2023, 11:18 AM
  3. Replies: 28
    Last Post: 08-27-2022, 10:18 AM
  4. [SOLVED] xlookup multiple criteria #Value!
    By justinwb in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 07-05-2022, 09:10 PM
  5. [SOLVED] XLOOKUP using INDIRECT with named range to search across multiple dynamic sheets
    By MangoFresh in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 06-02-2022, 11:24 AM
  6. Xlookup with multiple criteria
    By Mackay2m in forum Excel Formulas & Functions
    Replies: 21
    Last Post: 01-12-2022, 04:09 PM
  7. Replies: 7
    Last Post: 12-10-2021, 02:17 PM

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