Results 1 to 9 of 9

Using variables to determine a range for an average.

Threaded View

blastronaut Using variables to determine... 05-08-2011, 12:13 AM
tigertiger Re: Using variables to... 05-08-2011, 12:52 AM
blastronaut Re: Using variables to... 05-08-2011, 01:00 AM
tigertiger Re: Using variables to... 05-08-2011, 01:09 AM
blastronaut Re: Using variables to... 05-08-2011, 01:27 AM
blastronaut Re: Using variables to... 05-08-2011, 01:40 AM
tigertiger Re: Using variables to... 05-08-2011, 01:54 AM
tigertiger Re: Using variables to... 05-08-2011, 02:00 AM
blastronaut Re: Using variables to... 05-08-2011, 05:58 PM
  1. #1
    Registered User
    Join Date
    05-05-2011
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    36

    Using variables to determine a range for an average.

    Hello everybody!

    On Sheet1, B2 through B15600 will contain a list of numbers. I want to be able to take an average of a given amount of those cells and enter it into a corresponding cell in C. To do this, I would like to be able to enter 2 numbers on Sheet2 in cells B1 and B2. B1 will govern the range of cells and B2 will determine how many cells up from the cell in Column C that the range will end.

    For instance, if I entered the numbers 10 and 10, cell C20 would have the following formula "=Average(B2:B11)".

    I would also like it to be auto filled all the way to C15600.

    I am not very good at VBA yet but here is the code I have so far. It is giving me a "Compile Error: Expected End of Statement"

    Private Sub Worksheet_Change(ByVal Target As Range)
    
    Dim Length1 As Integer
    Dim Length2 As Integer
    
        Length1 = Sheets("Sheet2").Range("B1").Value
        Lenght2 = Sheets("Sheet2").Range("B2").Value
    
    Sheets("Sheet1").Range("b2:b15600").Formula = "=Average("Sheets("Sheet1").Range("b2:b15600").Selection.Offset(-(Length1+Length2), -1).Value":"Sheets("Sheet1").Range("b2:b15600").Selection.Offset(-(Length2), -1).Value")"
    
    End Sub

    Can you guys offer any help?
    Attached Files Attached Files
    Last edited by blastronaut; 05-13-2011 at 06:49 PM.

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