+ Reply to Thread
Results 1 to 9 of 9

Setting up a dynamically generated range reference

  1. #1
    Registered User
    Join Date
    02-21-2012
    Location
    Varna, Bulgaria
    MS-Off Ver
    Excel 2007
    Posts
    7

    Setting up a dynamically generated range reference

    Hi everyone,


    I am trying to adjust a dynamically generated range reference formula to integrate later in a SUMIF function.

    INDIRECT(CONCATENATE("AG","6:","AM","6"), where

    *"AG" & "AM" are dynamically generated column references and
    6 is a static row number that I want to make dynamic as well by replacing it with ROW() function as follows:

    INDIRECT(CONCATENATE("AG","6:","AM",ROW())

    The problem comes with the first number (6). It gives an error when trying to replace it with the ROW() function. Removing the quotes around it also doesn't help as it seems to break the consistency of the formula and it can't work without it.

    The thing is that I want to copy the SUMIF formula down and the row number to change according to the Row where the cell is situated.

    Row6: SUMIF($AG$5:$AM$5,"ITF",INDIRECT(CONCATENATE("AG","6:","AM","6")))
    Row7: SUMIF($AG$5:$AM$5,"ITF",INDIRECT(CONCATENATE("AG","7:","AM","7")))
    Row8: SUMIF($AG$5:$AM$5,"ITF",INDIRECT(CONCATENATE("AG","8:","AM","8")))

    Copy paste doesn't work, so I am looking for a workaround solution to make the static row number dynamic.
    Any suggestions outside the VBA functions will be appreciated. Maybe an alternative formula?

    Thanks,

    Cvetan
    Last edited by cveetan; 03-01-2012 at 12:48 PM.

  2. #2
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,737

    Re: Setting up a dynamically generated range reference

    First of all, there is no need to use the CONCATENATE function - use the concatenation operator & instead.

    Secondly, try this in row 6:

    SUMIF($AG$5:$AM$5,"ITF",INDIRECT("AG"&ROW(A6)&":AM"&ROW(A6)))

    The A6 will change as you copy it down and thus will return the range that you want.

    Hope this helps.

    Pete

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Setting up a dynamically generated range reference

    You just need to take the $ signs off the references you want to be relative and adjust as you copy down:

    Row6: =SUMIF($AG$5:$AM$5, "ITF", $AG6:$AM6)

    ...copy down.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  4. #4
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Setting up a dynamically generated range reference

    surely just
    =SUMIF($AG$5:$AM$5,"ITF",AG6:AM6) in row 6 will do?
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  5. #5
    Registered User
    Join Date
    02-21-2012
    Location
    Varna, Bulgaria
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Setting up a dynamically generated range reference

    Hey Pete, J, Martin,


    Thank you for your quick replies and suggestions.

    Surely I can enter the AG and AM manually
    =SUMIF($AG$5:$AM$5,"ITF",AG6:AM6)
    and then copy the formula down, however please remember that the "AG" and "AM" references are dynamically generated by formulas that need to be input to their places in this very SUMIF formula.

    So imagine it like this

    Row6: SUMIF($AG$5:$AM$5,"ITF",INDIRECT(CONCATENATE("AG","6:","AM","6")))

    "AG" replaced by IF(33,CHAR(ROUNDDOWN((33-1)/26,0)+64)&CHAR(MOD((33-1),26)+65),CHAR(33+64))
    "AM" replaced by IF(COLUMN(),CHAR(ROUNDDOWN((COLUMN()-1)/26,0)+64)&CHAR(MOD((COLUMN()-1),26)+65),CHAR(COLUMN()+64))

    and it looks like this

    =SUMIF($AG$5:$AM$5,"ITF",INDIRECT(CONCATENATE(IF(33,CHAR(ROUNDDOWN((33-1)/26,0)+64)&CHAR(MOD((33-1),26)+65),CHAR(33+64)),"6:",IF(COLUMN(),CHAR(ROUNDDOWN((COLUMN()-1)/26,0)+64)&CHAR(MOD((COLUMN()-1),26)+65),CHAR(COLUMN()+64)),"6")))

    Sorry, I don't know any other way to insert dynamically changeable range of cell references, except for the CONCATENATE formula.
    which works fine except for the static row number.

    @Pete, I've tried your way also but couldn't make it work it gives #REF! error when calculating though CTRL + SHIFT + ENTER

    It looks like this:

    =SUMIF($AG$5:$IN$5,"ITF",INDIRECT(IF(33,CHAR(ROUNDDOWN((33-1)/26,0)+64)&CHAR(MOD((33-1),26)+65),CHAR(33+64))&ROW(A6)&":IF(COLUMN(),CHAR(ROUNDDOWN((COLUMN()-1)/26,0)+64)&CHAR(MOD((COLUMN()-1),26)+65),CHAR(COLUMN()+64))"&ROW(A6)))

    Am i doing anything wrong? I believe this is the problematic area (in red)

    SUMIF($AG$5:$AM$5,"ITF",INDIRECT("AG"&ROW(A6)&":AM"&ROW(A6)))
    respectively in the originally suggested by me formula

    SUMIF($AG$5:$AM$5,"ITF",INDIRECT(CONCATENATE("AG","6:","AM","6")))
    So still wondering. If I manage to work it around I will let you know.


    Cheers,

    Cvetan

  6. #6
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Setting up a dynamically generated range reference

    works for me
    Attached Files Attached Files

  7. #7
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,737

    Re: Setting up a dynamically generated range reference

    Quote Originally Posted by cveetan View Post
    ...
    So imagine it like this

    Row6: SUMIF($AG$5:$AM$5,"ITF",INDIRECT(CONCATENATE("AG","6:","AM","6")))

    "AG" replaced by IF(33,CHAR(ROUNDDOWN((33-1)/26,0)+64)&CHAR(MOD((33-1),26)+65),CHAR(33+64))
    "AM" replaced by IF(COLUMN(),CHAR(ROUNDDOWN((COLUMN()-1)/26,0)+64)&CHAR(MOD((COLUMN()-1),26)+65),CHAR(COLUMN()+64))
    ...
    I've tried these as they are in various cells in a blank sheet. The first returns AG wherever it is placed, as "IF(33" is the same as saying "IF(TRUE" so it will always return AG - in that case why not replace it with "AG" ?

    The second expression is incomplete - I think it should be:

    =IF(COLUMN()>26,CHAR(ROUNDDOWN((COLUMN()-1)/26,0)+64)&CHAR(MOD((COLUMN()-1),26)+65),CHAR(COLUMN()+64))

    and this will return the column identifier for whichever column it is in (you might have considered the ADDRESS function).

    @Pete, I've tried your way also but couldn't make it work it gives #REF! error when calculating though CTRL + SHIFT + ENTER
    I'm not really sure why you would need CSE for this, but I think your amended formula should be (taking into account what I've said above):

    =SUMIF($AG$5:$AM$5,"ITF",INDIRECT("AG"&ROW(A6)&":"&IF(COLUMN()>26,CHAR(ROUNDDOWN((COLUMN()-1)/26,0)+64)&CHAR(MOD((COLUMN()-1),26)+65),CHAR(COLUMN()+64))&ROW(A6)))

    You had your quotes in the wrong place.

    Hope this helps.

    Pete

  8. #8
    Registered User
    Join Date
    02-21-2012
    Location
    Varna, Bulgaria
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Setting up a dynamically generated range reference

    Thanks Pete!


    All fixed now! I moved the quotes as you suggested and it worked like a charm.

    You are totally right about the static 33 formula, I've used it just as an example, cause I plan to place a more complex one in its place which shall not be a problem now that I have the placement of the second one resolved. ; )

    Thanks again for your assistance! Cheers pal!

    Cvetan

  9. #9
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,737

    Re: Setting up a dynamically generated range reference

    Glad to be of help. Perhaps you can mark the thread as Solved, and if there is any post that has particularly helped you then you can pass on thanks directly by clicking the "star" icon in the bottom left corner.

    Pete

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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