Playthisontheradio
New Member
Hi All!
As a learning exercise, I got the code below to do what I want - grab a set data and have the macro setup my statistical analysis formulas. This was very challenging for me as a novice.
I wanted to ask the forum for any color & commentary as to how & why this works, best practices, how to improve, and relevant resources. Would really appreciate any feedback.
This is in the ThisWorkbook module/object under Microsoft Excel Objects.
Thanks!
As a learning exercise, I got the code below to do what I want - grab a set data and have the macro setup my statistical analysis formulas. This was very challenging for me as a novice.
I wanted to ask the forum for any color & commentary as to how & why this works, best practices, how to improve, and relevant resources. Would really appreciate any feedback.
This is in the ThisWorkbook module/object under Microsoft Excel Objects.
Code:
Sub mystatcalc()
'Declare name of range to be set by user
Dim myData As Range
'Declare name of string type to be used in statistical calculation formulas placed into cells (stdev."S", for example)
Dim dType As String
'Get range from user to set myData
Set myData = Application.InputBox("Range:", Title:="Select data", Type:=8)
'Get "s" or "p" for statistical formulas to be placed into cells on workbook
dType = Application.InputBox("Population or sample:", Title:="Indicate data as sample or population", Type:=2)
'Put formulas into cells below myData as defined by user
Cells(myData.Rows.Count + myData.Row + 1, myData.Column).Formula = "=Average(" & myData.Address & ")"
Cells(myData.Rows.Count + myData.Row + 1, myData.Column + 1).Value = "Average"
Cells(myData.Rows.Count + myData.Row + 2, myData.Column).Formula = "=stdev." & dType & "(" & myData.Address & ")"
Cells(myData.Rows.Count + myData.Row + 2, myData.Column + 1).Value = "Stdev"
End Sub
Thanks!