I am hitting a limit when I try to assign a sum to a cells formula:
cells(y,x).formula = "=sum(G65,H74,I38,J20,G22, .... ,K19,L22)"
It seems as though I can't have more than 30 summands in a =sum formula.
Is there a workaround for this problem?
I am hitting a limit when I try to assign a sum to a cells formula:
cells(y,x).formula = "=sum(G65,H74,I38,J20,G22, .... ,K19,L22)"
It seems as though I can't have more than 30 summands in a =sum formula.
Is there a workaround for this problem?
You could group the cells by defining names for them or split the sum-formula into
=sum(...) + sum(...).
I would add a column to be used just for summing. It would contain a formula that pulls each row's number into the new column and then your sum formula for the code would look like this:
cells(y,x).formula = "=sum(Q1:Q100)"
Where Q1:Q100 would be the new column with the numbers to be summed.
You can cascade the sums as well:
cells(y,x).formula = "=sum(sum(G65,H74,...,I38,J20), sum(G22, .... ,K19,L22))"
Keep in mind that the formula length limit for Excel is 1,024 characters, so you might run into that limit if your formula needs to be much longer. If so, use other cells to act as intermediate formulas and sum them.
Options:
The theird option doesn't use an plus-signs, in case you're alergic.
Your example doesn't show it, but if all of your cells are in the same row or column and you're selecting individual sums to avoid intermediate calculations, consider using SUBTOTAL. See http://www.dailydoseofexcel.com/archives/2008/01/04/subtotals-ignoring-subtotals/