+ Reply to Thread
Results 1 to 4 of 4

VBA Range inside Functions not producing desired results

  1. #1
    Forum Contributor
    Join Date
    06-01-2014
    Location
    Riyadh, Saudi Arabia
    MS-Off Ver
    Microsoft 365
    Posts
    224

    Question VBA Range inside Functions not producing desired results

    Hi All,

    I have the following code, where I set some Ranges (using 2nd row to Last_row of some columns) and then try to use those ranges in my formulas.

    But the macro runs and doesn't give me the desired results, I am sure there is something wrong in the way I have written them. Please have a look let me know what needs to be corrected.

    HTML Code: 
    If I were to do these functions directly in Excel it would look like:

    in I2:
    =IFERROR(AGGREGATE(15,6,Diff_Names!$E$2:$E$726/((G2=Diff_Names!$B$2:$B$726)*(E2=Diff_Names!$C$2:$C$726)),1),"N/A")

    in J2 (ARRAY):
    {=IFERROR(INDEX(Diff_Names!$F$2:$F$726,MATCH(G2&E2&I2,Diff_Names!$B$2:$B$726&Diff_Names!$C$2:$C$726&Diff_Names!$E$2:$E$726,o),1),"N/A")}

    In the macro I am just trying to make the last row (726-MyLastRow) dynamic and setting up the ranges to use inside functions.

  2. #2
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    Re: VBA Range inside Functions not producing desired results

    Duplicated - see below.
    Last edited by rorya; 12-18-2019 at 09:55 AM.
    Rory

  3. #3
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    Re: VBA Range inside Functions not producing desired results

    You can't use VBA variable names in a formula. You need the address of those ranges, but it would be simpler to just use the addresses directly in the formulas and concatenate in the last row information - e.g.:

    Please Login or Register  to view this content.
    or more simply:

    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    06-01-2014
    Location
    Riyadh, Saudi Arabia
    MS-Off Ver
    Microsoft 365
    Posts
    224

    Re: VBA Range inside Functions not producing desired results

    Thanks a lot, learned something new today.

    Have a great day ahead...

+ 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. Look for a Specific Value in a Range and Return Desired Results
    By Allen43 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-10-2018, 04:51 PM
  2. [SOLVED] VBA producing unexpected results
    By trandle in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 09-20-2017, 09:43 AM
  3. [SOLVED] Programmatic Filter not producing desired result set
    By mayoorsubbu in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-19-2017, 08:36 AM
  4. Summing military time is not producing desired result in a specific cell
    By seanpod in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-11-2015, 11:15 AM
  5. Macro no longer producing desired data
    By xforum142riidax in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-20-2011, 03:25 PM
  6. Macro no longer producing desired data
    By xforum142riidax in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-20-2011, 01:19 PM
  7. [SOLVED] Help With Producing Results Please
    By Paul in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-18-2005, 01:06 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