How to create formula to sum with dynamic ranges? I just can't make the right syntax

tothakos999

So what I would like to do is add a sum formula to a cell, so it can be edited later(normally, not through vba). It sums up some cells, but the amount of cells is not always the same. Sometimes it's 4 cells, sometimes it's 10. So I'm trying to have:

lastrow = Sheets(7).Cells(Sheets(7).Rows.Count, "A").End(xlUp).Row

then using it:

Sheets(7).Range("B" & lastrow + 1).Formula = "=SUM(b2:b&"lastrow")"

My problem is the syntax actually, I can't seem to make it right. How to add lastrow to this formula?

Hope it's understandable, English is not my native language.

nagarajannd

You're missing to concatenate.

Sheets(7).Range("B" & lastrow + 1).Formula = "=SUM(b2:b" & lastrow & ")"

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Excel: Make a dynamic sum formula

How can I simplify this IF(SUM() formula?

How can I create a dynamic range in two directions? I want to use it for a minsif formula

How can I make my dynamic table create new rows when I input into a form? Right now it creates the row but it creates a new one on every click

Dynamic GETPIVOTDATA formula to SUM with different date ranges per column

I can't figure out how this loop not breaking and give the right value. It just keeps adding up

How can I dynamically determine the IP mask to use for dynamic ranges?

How to make the array in a formula dynamic?

How can i make the image on the right of the text

How can i make use of DOM Create Element to make the existing code more dynamic and concise?

How can I figure the just-right amount of Silver compound?

How can i filter and create ranges from NSIndexSet?

How can I make a dynamic value for update?

How can I make dynamic text fields

JavaScript - How can I make it more dynamic?

How can i make dynamic pl/sql?

How can I make Meteor subscriptions dynamic?

WPF: How can I make the view dynamic?

How can I make the locales dynamic in NextJS?

How can I make a dynamic select box?

How can I make dynamic parameter on the url?

How can i make this condition dynamic?

How can i make the for loop parameters dynamic

How i can make a dynamic css class?

How can I make actionListener method Dynamic

how can i make a dynamic context menu

How can I initialize a variable for UIViewController class in right syntax?

How to create dynamic ranges and Improving vba Code

How can I make this formula automatically update sheet reference?