See the attached Excel 2003 file (which is a copy of your file with additions) that
contains Macros that should get you started. I don't think it does exactly what you want,
since it hard codes the 'start cell' and the 'theoretical value' for each of the three calculations.
The Macros are included here:
Function CalculateFifteenMinuteAverage(xTheoreticalValue As Single, sStartCell As String) As Single
Dim jColumn As Long
Dim jEndRow As Long
Dim jStartRow As Long
Dim xAverage As Single
Dim xStandardDeviation As Single
jColumn = Sheet1.Range(sStartCell).Column
jStartRow = Sheet1.Range(sStartCell).Row
jEndRow = jStartRow + 15 - 1
xAverage = CSng(Application.WorksheetFunction.Average(Sheet1.Range(Cells(jStartRow, jColumn), Sheet1.Cells(jEndRow, jColumn))))
CalculateFifteenMinuteAverage = xAverage
End Function
Sub ClearDataFromYellowArea()
Const sRange = "E35:K44"
Range(sRange).ClearContents
End Sub
Sub CalculateThreeAverages()
Const sResultCOLUMN = "E"
Const sResultTheoreticalCOLUMN = "G"
Const nDatumResultROW = 34 'One less than the output start row
Dim iRow As Integer
Dim x As Single
Dim xTheoreticalValue As Single
Dim sStartCell As String
''''''''''''''''''''''''''''''''''''''''''''''''
'Initialization
''''''''''''''''''''''''''''''''''''''''''''''''
'Clear the old data (then wait 1 second)
Call ClearDataFromYellowArea
Application.Wait DateAdd("s", 1, Now)
'Assign the row prior to the Start Row
iRow = nDatumResultROW
iRow = iRow + 1
Sheet1.Cells(iRow, sResultCOLUMN) = "15 Minute Averages"
''''''''''''''''''''''''''''''''''''''''''''''''
'First Calculation
''''''''''''''''''''''''''''''''''''''''''''''''
xTheoreticalValue = 20#
sStartCell = "B32"
x = CalculateFifteenMinuteAverage(xTheoreticalValue, sStartCell)
iRow = iRow + 1
iRow = iRow + 1
Sheet1.Cells(iRow, sResultCOLUMN) = Format(x, "0.00")
Sheet1.Cells(iRow, sResultTheoreticalCOLUMN) = "Theoretical Value = " & xTheoreticalValue
''''''''''''''''''''''''''''''''''''''''''''''''
'Second Calculation
''''''''''''''''''''''''''''''''''''''''''''''''
xTheoreticalValue = 0#
sStartCell = "B65"
x = CalculateFifteenMinuteAverage(xTheoreticalValue, sStartCell)
iRow = iRow + 1
iRow = iRow + 1
Sheet1.Cells(iRow, sResultCOLUMN) = Format(x, "0.00")
Sheet1.Cells(iRow, sResultTheoreticalCOLUMN) = "Theoretical Value = " & xTheoreticalValue
''''''''''''''''''''''''''''''''''''''''''''''''
'Third Calculation
''''''''''''''''''''''''''''''''''''''''''''''''
xTheoreticalValue = 85#
sStartCell = "B117"
x = CalculateFifteenMinuteAverage(xTheoreticalValue, sStartCell)
iRow = iRow + 1
iRow = iRow + 1
Sheet1.Cells(iRow, sResultCOLUMN) = Format(x, "0.00")
Sheet1.Cells(iRow, sResultTheoreticalCOLUMN) = "Theoretical Value = " & xTheoreticalValue
End Sub
Bookmarks