+ Reply to Thread
Results 1 to 5 of 5

Sum variable number of columns in same row, but avoiding circular reference error

  1. #1
    Registered User
    Join Date
    08-28-2021
    Location
    London
    MS-Off Ver
    Excel
    Posts
    2

    Sum variable number of columns in same row, but avoiding circular reference error

    Hello all.

    This is my first post, and I'm a newcomer to Excel!

    I have tried to write a function to:
    • dynamically sum (ie the sum updates as additional columns of values typed) all values rightward of a certain cell along one row - D2 in this case.
    • If some of the intermediate cells along that row are blank, these need to be treated as having a value = zero

    However I can't figure out how to break out of the resulting circular reference.

    Here's the function in question, and the .xlsx is attached.
    =SUM(OFFSET(D2,0,0,1,COUNTA(2:2)))
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,089

    Re: Sum variable number of columns in same row, but avoiding circular reference error

    Hi & welcome to the board.
    How about
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    08-28-2021
    Location
    London
    MS-Off Ver
    Excel
    Posts
    2

    Re: Sum variable number of columns in same row, but avoiding circular reference error

    Thanks for the reply.

    I was trying to make it dynamic by not giving a fixed end cell for the SUM() array, so please explain how yours works, is ZZ2 sufficiently far away?

  4. #4
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,089

    Re: Sum variable number of columns in same row, but avoiding circular reference error

    As long as there is nothing to the right of the last cell you want to sum, you can just use a range that is large enough to cover your data. I just used ZZ as an example, but you could take it out to XFD

    I also try to avoid using the offset function as it's volatile. Added to which using Counta when you have blank cells in the range, will (most likely) give wrong results.

  5. #5
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,587

    Re: Sum variable number of columns in same row, but avoiding circular reference error

    In B2

    =SUM($C$2:INDEX(2:2,AGGREGATE(14,6,COLUMN($C$2:$XFD$2)/($C$2:$XFD$2>0),1)))

    Or

    =SUM($C$2:INDEX(2:2,LOOKUP(2,1/($C$2:$U$2>0),COLUMN($C$2:$U$2))))
    Attached Files Attached Files
    Last edited by kvsrinivasamurthy; 08-29-2021 at 04:34 AM.
    Pl note
    Array formula should be confirmed with Ctrl+Shift+Enter keys together.
    If answere is satisfactory press * to add reputation.

+ 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] Avoiding a Circular Reference
    By robotlust in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-06-2019, 07:57 PM
  2. [SOLVED] Avoiding Circular Reference
    By GroupStats in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-03-2013, 03:41 PM
  3. avoiding circular reference
    By dockdude in forum Excel General
    Replies: 2
    Last Post: 02-25-2010, 11:07 AM
  4. Avoiding Circular Reference
    By ffffloyd in forum Excel General
    Replies: 3
    Last Post: 07-01-2009, 06:56 PM
  5. [SOLVED] Macro avoiding circular reference
    By Kanga 85 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 03:05 AM
  6. Replies: 4
    Last Post: 05-06-2005, 07:06 AM
  7. [SOLVED] Avoiding a circular reference or value error while trying to calculate commission - a challange for me!
    By Bruce Johnson in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-06-2005, 07:06 AM

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