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?
Bookmarks