+ Reply to Thread
Results 1 to 8 of 8

Thread: simple sum formula question

  1. #1
    Forum Contributor
    Join Date
    01-13-2006
    Location
    Texas
    Posts
    141

    simple sum formula question

    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

    FinalRow = Range("B65536").End(xlUp).Row
    to determine the bottom row. Two cells below that bottom row, I want to insert a sum of all the numbers above it.

    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.

  2. #2
    Registered User
    Join Date
    06-29-2011
    Location
    California
    MS-Off Ver
    Excel 2003/2007
    Posts
    58

    Re: simple sum formula question

    "=sum(B4:B" & x & ")"
    is the correct syntax for including a variable titled 'x'

  3. #3
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,640

    Re: simple sum formula question

    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)

  4. #4
    Registered User
    Join Date
    06-29-2011
    Location
    California
    MS-Off Ver
    Excel 2003/2007
    Posts
    58

    Re: simple sum formula question

    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.

  5. #5
    Forum Contributor
    Join Date
    01-13-2006
    Location
    Texas
    Posts
    141

    Re: simple sum formula question

    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:


    Range("B" & FinalRow + 2).Select
     ActiveCell.Formula = "=SUM(B4:B & FinalRow)"
    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.

    Thanks again for any more feedback.

  6. #6
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,640

    Re: simple sum formula question

    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)

  7. #7
    Forum Contributor
    Join Date
    01-13-2006
    Location
    Texas
    Posts
    141

    Re: simple sum formula question

    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.

  8. #8
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,640

    Re: simple sum formula question

    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)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0