Sum column if cells are outside range (range = leftmost value in row + next 11 columns) R or Excel?

前端 未结 2 1805
礼貌的吻别
礼貌的吻别 2021-01-27 19:21

Please see the picture. In the matrix pictured, an entry is considered \"New Business\" from the leftmost value + the next 11 columns (so 12 months total). I\'ve highlighted thi

2条回答
  •  耶瑟儿~
    2021-01-27 19:57

    This shouldn't be too difficult to do in VBA. Rather than just writing all of the code for you, I will set out how I would plan to approach this and suggest that you at least have a go at the code yourself, then open further questions for any specifics you are stuck on.

    I would look to do something like the following:

    1. Specify the range that you are working with;
    2. Loop through each row getting the new business and return business values and adding them to cumulative totals;
    3. On each row use a function to determine the first used row (e.g. .End(xlToRight) from column B on the current row may be helpful), then sum the range from this to a column offset of 12 to get the new business for that row and use this to derive the return business as you suggested;
    4. Use your cumulative totals to update the fields required.

    If you are stuck with any syntax manually performing the steps whilst recording a macro then looking at the code generated can often help.

提交回复
热议问题