+ Reply to Thread
Results 1 to 5 of 5

Sum adjacent cells in a range until a cell with a different value is detected

  1. #1
    Registered User
    Join Date
    11-30-2020
    Location
    Switzerland
    MS-Off Ver
    2010
    Posts
    2

    Lightbulb Sum adjacent cells in a range until a cell with a different value is detected

    Hi,

    I am new in the forum and I have looked up similar topics but couldn't find the answer that would suit me. I am stuck in doing one analysis, not able to find the right formula, so here is the issue:

    I have a set of binary values in my file (for simplicity I have reduced the range to A2:K7, while in the real file I would have around 1500 rows for each date of 2020 and 2021). On the right (L2:V7) there is the desired outcome and the formula I am looking for should do the following: once the value in the raw data set is 1, it should evaluate the adjacent cells on the left and should check how many consequent 1 values there are and sum them. Once it encounters a cell with 0 it should not count further. E.g in the raw 7 in my file when it evaluates the cell K7 with a simple IF statement - IF(K7=1, ..., 0) --- it should sum the values up to cell F7 because in E7 there is a zero and it should stop the evaluation. In V7 it should reflect the sum.

    I tried SUMPRODUCT but wasn't really successful. Does anybody have an idea here?
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    09-22-2019
    Location
    Ottawa, Canada
    MS-Off Ver
    2003/2010/2013/2016
    Posts
    3

    Re: Sum adjacent cells in a range until a cell with a different value is detected

    Sorry, I tried reading your paragraph but don't really understand.

    Give pasting this formula in cell M4 and it should match what you had, not sure if it's what you're looking for though. Note that wednesday needs to be left as 0s, need to deal with that edge case.

    =IF(AND(B4=1,A4=1),L4+B4,0)

  3. #3
    Forum Expert
    Join Date
    07-06-2004
    Location
    Northern California
    MS-Off Ver
    2K, 2003, 2010, O365
    Posts
    1,490

    Re: Sum adjacent cells in a range until a cell with a different value is detected

    L4:L7 would all be 0 since there are no cells to the left of A4:A7.

    M4: =B4*(L4+A4)

    Copy M4, select M4:V7, paste.

  4. #4
    Registered User
    Join Date
    11-30-2020
    Location
    Switzerland
    MS-Off Ver
    2010
    Posts
    2

    Re: Sum adjacent cells in a range until a cell with a different value is detected

    Hey, thanks a lot, both seem to be working. I knew it was supposed to be simple, but it was incorporated in a larger analysis with more complex formulas, so I was convinced at a certain point I needed something complicated here too

  5. #5
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,830

    Re: Sum adjacent cells in a range until a cell with a different value is detected

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

    Also, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

+ 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 up cell value in range of cells and copy adjacent cell.
    By OvertOddity in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-03-2016, 05:41 PM
  2. Replies: 1
    Last Post: 04-11-2014, 01:48 PM
  3. How can I hide certain adjacent cells if a specific cell is in a range value.
    By Losttwinky in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 11-24-2013, 04:35 PM
  4. [SOLVED] Matching cell to range, and copying adjacent cells.
    By BPSJACK in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-14-2012, 12:11 PM
  5. [SOLVED] Find empty cells in a range and insert formula in adjacent cell
    By macronovice1 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-25-2012, 03:06 PM
  6. [SOLVED] sum all cells in a row until first cell with a zero is detected
    By Chubster in forum Excel General
    Replies: 9
    Last Post: 03-20-2012, 06:06 PM
  7. Exit a macro if cells of a certain colour are detected in a range of cells
    By niks in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-13-2011, 11:02 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