简体   繁体   中英

Array formula to sum dynamic range

i have data that looks like this .

I want to insert an array formula, which will sum specific range based on user's choice. If the user chose for example "3", i want an array formula to Sum absolute value of 3 last columns (D,E,F) for each row (rows are also dynamic - there could be 10,50 or more rows). Last column is always in the same place, the starting point change. How can i do that?

Assuming your data starts in cell A1 and the number of columns chosen is in H6 and you are using dynamic array excel then try this formula:

=SUM(ABS(INDEX(A1#,SEQUENCE(ROWS(A1#),1),SEQUENCE(1,COLUMNS(A1#)-H6+1,H6))))

To enter into cell Z9 using vba if nCols contains the number of columns try this:

Range("Z9").formula2="=SUM(ABS(INDEX(A1#,SEQUENCE(ROWS(A1#),1),SEQUENCE(1,COLUMNS(A1#)-" & nCols & "+1," & nCols & "))))"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM