First, I would be amazed if this hasn't been answered before, but I cannot get the forum search to function correctly. So...
I have a single workbook open, with a single worksheet.
I want to sum a column where I know the top row, but I am using
to determine the bottom row. Two cells below that bottom row, I want to insert a sum of all the numbers above it.FinalRow = Range("B65536").End(xlUp).Row
For example, I want to sum B4:Bx. So in cell Bx+2, I want the formula "=sum(B4:Bx)"
I simply cannot come up with the syntax for this simple process. Any help would be much appreciated. Thank you in advance.
Conor
Last edited by Conor; 07-03-2011 at 02:36 PM.
is the correct syntax for including a variable titled 'x'"=sum(B4:B" & x & ")"
Something like
finalrow = Range("B65536").End(xlUp).Row Cells(finalrow + 2, 2).Formula = "=sum(B4:B" & finalrow & " )"
Hope that helps.
RoyUK
--------
If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need
For Excel Tips & Solutions, free examples and tutorials why not check out my downloads
New members please read & follow the Forum Rules
Remember to mark your questions Solved and rate the answer(s)
It depends whether or not he's typing the code into a spreadsheet, or adding it via vba. Since he provided a vba code at the start, i assumed he wanted to execute this from within vba, which means the code I supplied is correct.
Thanks for the quick responses. I'm sorry, perhaps I was not clear. I thought it was that simple. I am executing a macro, so the lines in question currently read:
However, when I execute the macro, which does other things also, the cell with address B & FinalRow +2 gives the result #NAME?, so I must be doing something wrong.Range("B" & FinalRow + 2).Select ActiveCell.Formula = "=SUM(B4:B & FinalRow)"
Thanks again for any more feedback.
Have a look at my answer, it's not the same as your formula. Also, you don't need to select the cell to place the formula in it
Hope that helps.
RoyUK
--------
If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need
For Excel Tips & Solutions, free examples and tutorials why not check out my downloads
New members please read & follow the Forum Rules
Remember to mark your questions Solved and rate the answer(s)
Thank you gentlemen. I did not wish to provoke any disagreement. I have the answer. I think it was that final &" within the parans that was throwing me. I definitely appreciate the input from both of you. If I can figure it out, I will update as solved. thanks again.
Last edited by Conor; 07-03-2011 at 02:14 PM.
Conor my answer was to you about the difference in formulas.
I originally thought that Docmed was posting something different, I didn't see his next post.
Hope that helps.
RoyUK
--------
If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need
For Excel Tips & Solutions, free examples and tutorials why not check out my downloads
New members please read & follow the Forum Rules
Remember to mark your questions Solved and rate the answer(s)
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks