+ Reply to Thread
Results 1 to 3 of 3

Excel 2007 : Finding The Average of the Last 20 Cells in a Column

Hybrid View

  1. #1
    Registered User
    Join Date
    05-01-2012
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2007
    Posts
    2

    Finding The Average of the Last 20 Cells in a Column

    Hi All,

    This should be simple, but I'm being extra gumbylike today, so I cannot figure it out.

    I am trying to find the value of the last 20 cells in a column and paste it into one cell. The number of rows in the spreadsheet will vary from instance to instance.

    Any help or suggestions you could provide would be much appreciated.

    Just to prove what a gumby I am, here is my current code from my attempts to make this happen:
    Sub Determine_Offset()
    
    Dim LastTwenty As Range
    Dim LastTwentyAverage As Double
    
    Range("G1").Select
    Range("F1").End(xlDown).Select
    Set LastTwenty = ActiveCell.Offset(-20, 0).Range("A1:A21")
    'LastTwentyAverage = [Average(Range("F1:F21"))]
    'ActiveCell.Value = LastTwentyAverage
    ActiveCell.Formula "=AVERAGE(Range(LastTwenty).Cells)"
    
    
    End Sub
    Thanks!

    Ebikeguy
    Last edited by arlu1201; 05-01-2012 at 02:52 PM. Reason: Please put code tags in future.

  2. #2
    Forum Expert
    Join Date
    09-27-2011
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    1,312

    Re: Finding The Average of the Last 20 Cells in a Column

    hi I do not understand Your code but let's say You have data in column A than below code will count average of last 20 cells and will put the result in B1
    Sub Determine_Offset()
    
    Dim last As Long
    last = Cells(Rows.Count, 1).End(xlUp).Row
    Range("b1") = Application.WorksheetFunction.Average(Range("a" & last & ":" & "a" & last - 19))
    
    End Sub
    Last edited by tom1977; 05-01-2012 at 02:51 PM.
    Regards

    tom1977

    If You are satisfied with my solution click the small star icon on the left to say thanks.

  3. #3
    Registered User
    Join Date
    05-01-2012
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Finding The Average of the Last 20 Cells in a Column

    Worked perfectly! Thank you very much! I'm so glad I found this forum!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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