PDA

View Full Version : Simple input and data problem



Techgirl
09-21-2011, 01:14 PM
I'm very new to vba and have no idea how to approach this problem. Would anybody like to help?

My goal is to modify this code (at the bottom) so that a user can designate a number larger than 1 and less than 101 through an input box to choose how many "scores" to calculate statistcs on. I have an excel sheet with cells a1 - a100 with random scores to calculate.



Dim msg As String

msg = "Here are summary measures for the scores:"
msg = msg & vbCrLf & "Average:" & vbTab & Application.WorksheetFunction.Average(Range("A1:A200"))
msg = msg & vbCrLf & "Stdev:" & vbTab & _
Format(Application.WorksheetFunction.StDev(Range("A1:A200")), "0.00")
msg = msg & vbCrLf & "Min:" & vbTab & Application.WorksheetFunction.Min(Range("A1:A200"))
msg = msg & vbCrLf & "Max:" & vbTab & Application.WorksheetFunction.Max(Range("A1:A200"))
MsgBox msg, vbInformation




hopefully I have provided enough information for anyone to follow me.. thanks for reading any help is appreciated :thumb

GTO
09-21-2011, 01:44 PM
How about:
Sub exa4()
Dim rngPicked As Range
Dim msg As String

On Error Resume Next
Set rngPicked = Application.InputBox("Pick the range you want to run against.", "My Title", , , , , , 8)
On Error GoTo 0

If Not rngPicked Is Nothing Then
msg = "Here are summary measures for the scores:"
msg = msg & vbCrLf & "Average:" & vbTab & Application.WorksheetFunction.Average(rngPicked)
msg = msg & vbCrLf & "Stdev:" & vbTab & _
Format(Application.WorksheetFunction.StDev(rngPicked), "0.00")
msg = msg & vbCrLf & "Min:" & vbTab & Application.WorksheetFunction.Min(rngPicked)
msg = msg & vbCrLf & "Max:" & vbTab & Application.WorksheetFunction.Max(rngPicked)

MsgBox msg, vbInformation, "Results"
End If
End Sub

Techgirl
09-21-2011, 02:58 PM
Looks great! thanks for the help, you deserve some real life karma

GTO
09-21-2011, 05:06 PM
Hi Techgirl,

Happy to help and welcome to vbaexpress!

Mark