+ Reply to Thread
Results 1 to 13 of 13

Dynamic Name Range

  1. #1
    Registered User
    Join Date
    03-05-2007
    Location
    Colorado Springs, CO
    MS-Off Ver
    2010
    Posts
    45

    Dynamic Name Range

    I am crushing my spreadsheet with maxif arrays to the point where it's running out of memory because i'm referring to entire columns. My data set changes constantly so I can't hard code the number of rows I have in my sheet.

    I have been searching the forum trying to understand how fix this so that I only use the number of rows in my dataset.

    I am trying to grasp the concept of naming a data range dynamically. I'm referring to the "pulling out minimum and maximum values..!" thread from this morning. I've downloaded the excel example and trying to understand the calls to the range as well as the formation of the named range.

    Name: _Data

    Refers to: =aaaa!$A$2:INDEX(aaaa!$C:$C,MATCH(9.99E+307,aaaa!$C:$C))

    In this example, can you explain what the INDEX MATCH are doing to name this range dynamically?

    Thanks!

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Dynamic Name Range

    The MATCH returns the row number of the last number to be found in Column C.

    The INDEX takes the MATCH result to create a range reference

    Assume last number appears in row 10 of column C, the named range thus becomes:

    Please Login or Register  to view this content.
    obviously your range above spans three columns which may or may not be required

    If you have a multi column defined name and wish to work only with a specific column you can use a further INDEX in your standard functions, eg:

    Please Login or Register  to view this content.
    which would return the MAX of the last column in the range (as specified by 3; the 0 for row tells INDEX to return all rows)

  3. #3
    Registered User
    Join Date
    03-05-2007
    Location
    Colorado Springs, CO
    MS-Off Ver
    2010
    Posts
    45

    Re: Dynamic Name Range

    Sorry I'm just getting back to the forum. I have been traveling.

    Thank you...that is very helpful. The 9.99E+307 is what was throwing me off...is that telling excel to find the last row?

    Also, if I do a Max(if) statement on this range, I'm assuming I still have to turn it into an array, right? is there a better way to do a conditional max statement?

    Thanks again! I tried to give you more "props" but it wouldn't let me.

  4. #4
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Dynamic Name Range

    That's what's known as a BigNum.

    This might help explain it:

    http://www.mrexcel.com/forum/showthread.php?t=18954

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  5. #5
    Registered User
    Join Date
    03-05-2007
    Location
    Colorado Springs, CO
    MS-Off Ver
    2010
    Posts
    45

    Re: Dynamic Name Range

    Thanks Domski! I appreciate the read. I will have to read it a few times to make sure that I comprehend all the info in that article.

    I'm guessing that there is no better way to do the Maxif
    Last edited by DonkeyOte; 02-06-2011 at 05:01 AM. Reason: removed unnecessary quote

  6. #6
    Valued Forum Contributor
    Join Date
    09-21-2003
    Location
    British Columbia , Canada
    MS-Off Ver
    03,07,10,13
    Posts
    727

    Re: Dynamic Name Range

    Hi olsoniv:
    If your computer is not handling the formula well you might want to think about a macro instead .. is that something you'd like to explore ?

  7. #7
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Dynamic Name Range

    @olsoniv, when working with huge data sets etc the #1 key to efficient calculations (IMO) is ensuring the data set is sorted appropriately.

    Consider a data set of:

    A1:A40000: Alphas
    B1:B40000: Alphas
    C1:C40000: Alphas
    C1:C40000: Numbers
    Let's further assume we wish to:

    Return MAX of C where A = "x", B = "y" and C = "z"
    (to be repeated for a multitude of other combinations which may/may not exist)

    First things first it makes sense to create a "key" of the items of interest to reduce no. of comparative tests we need to perform:

    Please Login or Register  to view this content.
    the use of delimiters is important as you can adapt below to incorporate wildcard-esque searches


    Q: Is Data Set - Sorted ?

    A: No:

    we're left with an Array approach (assume Pivots [intermediate/final] not viable)

    Please Login or Register  to view this content.
    As we know Arrays are "expensive" in terms of resource so this approach is going to be slow.

    A: Yes - by A (A to Z), B (A to Z) and C (A to Z)

    with the data set sorted as outlined we can use more efficient approaches

    Please Login or Register  to view this content.
    the above repeated over and over will prove far quicker than the unsorted/Array approach simply because we're only calculating the MAX of a specific range (identified by INDEX & MATCH calls)

    [obviously in a real file the constant references to ^x^y^z^ would be replaced by a function concatenating values of interest]


    If you can't sort your data I would advise creating an intermediate Pivot table to calculate the MAX etc for the various combinations and then a basic GETPIVOTDATA call to retrieve the appropriate values.


    If you need assistance specific to your file you will need to post a sample
    Last edited by DonkeyOte; 02-06-2011 at 05:16 AM.

  8. #8
    Registered User
    Join Date
    03-05-2007
    Location
    Colorado Springs, CO
    MS-Off Ver
    2010
    Posts
    45

    Re: Dynamic Name Range

    Data cannot be sorted. I love the key idea! when performing wildcard searches, i'm assuming I use the "match" function and use the "*" wildcards between delimiters?
    Please Login or Register  to view this content.
    would evaluate to true... This worked in my tests but i just wanted to check to make sure I wasn't missing a more efficient way to do this.
    Last edited by olsoniv; 02-06-2011 at 06:24 PM. Reason: wrong tags for code.

  9. #9
    Registered User
    Join Date
    03-05-2007
    Location
    Colorado Springs, CO
    MS-Off Ver
    2010
    Posts
    45

    Re: Dynamic Name Range

    Quote Originally Posted by nimrod View Post
    Hi olsoniv:
    If your computer is not handling the formula well you might want to think about a macro instead .. is that something you'd like to explore ?
    @Nimrod - thanks for the suggestion and I may have to look at macro's down the line but trying to avoid them.

  10. #10
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Dynamic Name Range

    Quote Originally Posted by olsoniv
    i'm assuming I use the "match" function and use the "*" wildcards between delimiters?
    How best to utilise wildcard approach would largely depend on context but in the case of this type of Array, yes, a MATCH approach would be logical.

    Using:

    Please Login or Register  to view this content.
    tells XL that the first item is irrelevant

    Please Login or Register  to view this content.
    tells XL that the 21st century is significant

    other functions like COUNTIF etc accept wildcards and so you can perform multi criteria tests using this method - useful pre XL2007 (and introduction of the IFS)

  11. #11
    Registered User
    Join Date
    03-05-2007
    Location
    Colorado Springs, CO
    MS-Off Ver
    2010
    Posts
    45

    Re: Dynamic Name Range

    OK...so I'm still struggling with this thing and feel that i must be doing something stupid. I've attached an example book so you can see exactly what I'm trying to do.

    Dynamically count the arrays using BigNum as suggested while leaving out the "" results from a formula (in this case I just did ="" for the example)
    and then find the max min and average using the key and year to filter the results.
    Please Login or Register  to view this content.
    I also tried with match and got no result as well.

    I appreciate your continued guidance on this issue. I am very frustrated that I haven't been able to work this out on my own and need to keep bugging you on the matter.

    Thanks in advance.
    Attached Files Attached Files
    Last edited by olsoniv; 02-09-2011 at 04:57 PM. Reason: code tags

  12. #12
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Dynamic Name Range

    Your DNR ArrayKey is defined incorrectly - your MATCH of BigNum in Col A will return an error given no numbers in A.

    In reality it would make sense to size each range based on a consistent column, so define all based on match of BigNum in Col B for ex.

    Please Login or Register  to view this content.
    With the above corrected you can then work on your MAX Arrays

    When you use wildcards in a MATCH you must use an exact match_type as final parameter.
    This argument is by default optional and if omitted TRUE/1 is assumed (not an exact match - errs towards binary search for efficiency reasons)

    Please Login or Register  to view this content.
    note the ,0 after ArrayKey in the MATCH
    (0 could equally be FALSE given 0 & FALSE are in this context the same thing)

    The 2nd MAX approach won't work as a x=y won't allow for wildcards.

    If you only ever need to look for a single year at any given time you could add year to the key itself.

  13. #13
    Registered User
    Join Date
    03-05-2007
    Location
    Colorado Springs, CO
    MS-Off Ver
    2010
    Posts
    45

    Re: Dynamic Name Range

    Thanks so much! I REALLY appreciate all your time/help. Your answers work in the example perfectly...now off to implement in my actual workbook.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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