+ Reply to Thread
Results 1 to 10 of 10

Moving a sum to top

  1. #1
    Registered User
    Join Date
    06-21-2022
    Location
    Portland, Maine
    MS-Off Ver
    Excel 2010
    Posts
    5

    Question Moving a sum to top

    I have a sheet with hundreds of cells in a column, sometimes over 700.
    I have a VBA sub that sums the values in the cells:

    Sub AddRainColumn()
    Sheets("Rain").Select
    Range("A" & Rows.Count).End(xlUp).Offset(1).Select
    ActiveCell.FormulaR1C1 = "=SUM(R[-991]C:R[-1]C)"
    End Sub


    In order seen the sum I have to go all the way to the last cell in the column.
    I need a way to sum the cells and put the sum at the top of the sheet.
    Any idea how I can do this?
    Thanks.

  2. #2
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Moving a sum to top

    I am no VBA expert but you could try this one.

    Range("B1").FormulaR1C1 = "=SUM(R[-991]C:R[-1]C)"
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

  3. #3
    Forum Expert
    Join Date
    10-11-2021
    Location
    Netherlands
    MS-Off Ver
    365
    Posts
    1,386

    Re: Moving a sum to top

    You don't need VBA for this. Just paste the sum function at the top instead.
    That is what you are doing after all

  4. #4
    Valued Forum Contributor
    Join Date
    10-12-2021
    Location
    CT
    MS-Off Ver
    365
    Posts
    462

    Re: Moving a sum to top

    Please Login or Register  to view this content.
    change "B1" to where you want the results, and change the range (D2:D) to whatever column you want

  5. #5
    Valued Forum Contributor
    Join Date
    10-12-2021
    Location
    CT
    MS-Off Ver
    365
    Posts
    462

    Re: Moving a sum to top

    lol yeah, my code just puts the formula in a cell, it's not really vba

  6. #6
    Valued Forum Contributor
    Join Date
    10-12-2021
    Location
    CT
    MS-Off Ver
    365
    Posts
    462

    Re: Moving a sum to top

    This code prompts the user which column they want to sum... but JEC's advice to write a sum formula in a cell is the easiest method

    Please Login or Register  to view this content.
    Last edited by carlmon; 06-21-2022 at 01:52 PM.

  7. #7
    Registered User
    Join Date
    06-21-2022
    Location
    Portland, Maine
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Moving a sum to top

    Sorry, that didn't work. It just left a 0 in the B1 cell.
    But thanks, anyway.

  8. #8
    Registered User
    Join Date
    06-21-2022
    Location
    Portland, Maine
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Moving a sum to top

    This function is just a part of a larger program that collects weather data from a .cvs file.
    It splits the data into sheets, and the Rain sheet data is just the last one.
    Thanks, anyway.

  9. #9
    Registered User
    Join Date
    06-21-2022
    Location
    Portland, Maine
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Moving a sum to top

    Thanks, everyone.
    None of your suggestions worked quite the way I wanted.
    I have another idea I want to try.
    CU

  10. #10
    Registered User
    Join Date
    06-21-2022
    Location
    Portland, Maine
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Moving a sum to top

    Boy, I must have had a brain stoppage. (After all, I am 80 years old)
    This is my new sub and it works really well.

    Sub AddRainColumn()
    Range("D2").Select
    ActiveCell.FormulaR1C1 = "Rain Amount"
    Range("D3").Select
    Range("A" & Rows.Count).End(xlUp).Offset(1).Select
    ActiveCell.FormulaR1C1 = "=SUM(R[-991]C:R[-1]C)"
    Selection.Copy
    Selection.End(xlUp).Select
    Range("D3").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    End Sub


    Thanks for all your help. Sometimes just viewing help code from Excel people triggers a new thought.
    CU


    How do I mark this as finished?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 1
    Last Post: 10-20-2014, 03:20 PM
  2. Replies: 9
    Last Post: 07-29-2014, 11:41 AM
  3. Replies: 0
    Last Post: 05-21-2012, 06:59 AM
  4. Copying moving range based on moving cell reff.
    By Varmark in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-19-2011, 04:47 AM
  5. Charts 5 day moving average, 10 day moving average
    By monalisa in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-28-2008, 09:50 PM
  6. Moving average of a moving average in the same cell
    By philroberts1983 in forum Excel General
    Replies: 8
    Last Post: 09-16-2008, 07:36 AM
  7. Replies: 3
    Last Post: 02-17-2006, 12:15 AM

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