need macro to get date and export the average

hjason315

New Member
Joined
Jul 11, 2011
Messages
19
Hello all,

I have a huge data file that contains 16000 rows in Col B. And I need to scan 200 rows at a time, and IF the Standard Deviation is LESS THAN 0.05, export the average of these 200 numbers to Col E.

I do not have much VBA knowledge to write a code that can scan 200 rows at a time. Is there anyone can help me please:confused: Your help would be greatly appreciated!

Jason
 
I don't. Try this:

Code:
Sub CalcStDev()
Dim i As Long, LastRow As Long
Dim stDev As Double, stAverage As Double
 
LastRow = Range("B65536").End(xlUp).Row - 199
If Not LastRow < 1 Then
For i = 1 To LastRow
stDev = Application.WorksheetFunction.stDev(Range(Cells(i, 2), Cells(i + 199, 2)))
If stDev < 0.05 Then
stAverage = Application.WorksheetFunction.Average(Cells(i, 2), Cells(i + 199, 2))
    Cells(i, 5).Formula = "Rows " & i & " to " & i + 199 & " average is: " & stAverage
End If
Next i
End If
End Sub






That's 6.85 right just formatted to Scientific?

It is formatted as Scientific. still couldn't figure out.
For this macro, is there any restrictions for the numbers in Col B ? The numbers I have are all contains 5 or 6 numbers after decimal point.
 
Upvote 0

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
It is formatted as Scientific. still couldn't figure out.
For this macro, is there any restrictions for the numbers in Col B ? The numbers I have are all contains 5 or 6 numbers after decimal point.

never mind, I think I found out the reason.
Missing "Range" when doing average
Let me try this again
 
Upvote 0
I don't. Try this:

Code:
Sub CalcStDev()
Dim i As Long, LastRow As Long
Dim stDev As Double, stAverage As Double
 
LastRow = Range("B65536").End(xlUp).Row - 199
If Not LastRow < 1 Then
For i = 1 To LastRow
stDev = Application.WorksheetFunction.stDev(Range(Cells(i, 2), Cells(i + 199, 2)))
If stDev < 0.05 Then
stAverage = Application.WorksheetFunction.Average(Cells(i, 2), Cells(i + 199, 2))
    Cells(i, 5).Formula = "Rows " & i & " to " & i + 199 & " average is: " & stAverage
End If
Next i
End If
End Sub




That's 6.85 right just formatted to Scientific?


Thank you so much. This macro works great! just need to add Range after Average.
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,289
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top