+ Reply to Thread
Results 1 to 5 of 5

Do while with worksheetfunction.sum not working

  1. #1
    Forum Contributor timtim89's Avatar
    Join Date
    01-05-2012
    Location
    Copenhagen, Denmark
    MS-Off Ver
    Excel 2010
    Posts
    141

    Do while with worksheetfunction.sum not working

    Hey there!

    Need a bit of assistance with this one, so hopefully someone can help me out.

    I have a number of rows for which I, at the end of every second row, need a sum function (summing number in the row below).
    The number of columns, which are to be summed, varies, why I set a variable to the number of columns that are to be summed.
    Also, the number of rows, for which I need the sum function applied, varies. I tried to get around it with a Do while loop, but I get an error message on the worksheetfunction. Also at the very end of my loop, I need a total sum that sums together all the loop-generated sums. Not sure if I can somehow know where the loop ends, and thereby where this total sum will go?

    Please take a look at the attachment, cause it explains it better i hope The code I got so far is below. Another problem is, how do I hide the row below the activerow as well as the activerow, when the condition in the IF statement is met AND move the activecell in order to continue the loop. Thanks again.

    Please Login or Register  to view this content.
    Thanks in advance!
    Attached Files Attached Files
    Last edited by timtim89; 05-20-2012 at 07:45 PM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Do while with worksheetfunction.sum not working

    Try this instead. It's more straightforward and you can see formulas in the resulting cells so you can verify the data range is properly defined for each value.

    Please Login or Register  to view this content.

    The only caveat here is that column C is expected to be empty below the data set, your notes on your sheet seem to indicate this is the case.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Contributor timtim89's Avatar
    Join Date
    01-05-2012
    Location
    Copenhagen, Denmark
    MS-Off Ver
    Excel 2010
    Posts
    141

    Re: Do while with worksheetfunction.sum not working

    Beautiful! I see that your way is far more elegant than the one I was going for.
    No problem with the C column. Ill make sure it is empty below the data set. Still one problem though:
    In the total sum I only want the sum of the even rows (that is, the red cells in my attachment). Right now the total sum will be too high, cause of the the non yellow cells making a sum as well.
    How do I get around this? I tried to change your IF statement to
    Please Login or Register  to view this content.
    but got an error message.
    Also I'm still unfamiliar with the "R way" of refering to cells. What is the name of this, if I want to google and find out?

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Do while with worksheetfunction.sum not working

    The formula I gave you (in my testing at least) does not put Sums in the rows without text in column C. Yours does?

    Working properly, the SUM at the bottom should be fine.

  5. #5
    Forum Contributor timtim89's Avatar
    Join Date
    01-05-2012
    Location
    Copenhagen, Denmark
    MS-Off Ver
    Excel 2010
    Posts
    141

    Re: Do while with worksheetfunction.sum not working

    Ok got it to work now. Thanks again!

+ 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.6.0 RC 1