I am trying to write a macro that will allow users to input a last name and three scores for a number of people. Median class (as in school classrrom) values (and interquartile ranges) are calculated. The user is then prompted for the historical values for each trial and the final test. Then I would like to prompt the user to specify the range of cells corresponding to one student (or participant) to be plotted against his or her classmates and the historical course values. I believe I have accomplished all of this except for the plotting portion. After searching the internet for 3 days I cannot find a suitable example of how I need to specify the variables for plotting. (I do know I should have an "Options Explicit" statement and variables should be named better, etc but wanted to get the code correct first. Below is an example of data. TIA for your help!
<tbody>
</tbody>
================= CUT HERE FOR CODE ==================
Public Sub Graph1()
Range("B2").Select
ActiveCell.Value = InputBox("Enter Participant 1 Name")
Range("C2").Select
ActiveCell.Value = InputBox("Enter Participant 1, Trial 1 Score")
Range("D2").Select
ActiveCell.Value = InputBox("Enter Participant 1, Trial 2 Score")
Range("E2").Select
ActiveCell.Value = InputBox("Enter Participant 1, Trial 3 Score")
Range("F2").Select
ActiveCell.Value = InputBox("Enter Participant 1, Test Score")
Range("B3").Select
ActiveCell.Value = InputBox("Enter Participant 2 Name")
Range("C3").Select
ActiveCell.Value = InputBox("Enter Participant 2 Trial 1 Score")
Range("D3").Select
ActiveCell.Value = InputBox("Enter Participant 2, Trial 2 Score")
Range("E3").Select
ActiveCell.Value = InputBox("Enter Participant 2, Trial 3 Score")
Range("F3").Select
ActiveCell.Value = InputBox("Enter Participant 2, Test Score")
Range("B4").Select
ActiveCell.Value = InputBox("Enter Participant 3 Name")
Range("C4").Select
ActiveCell.Value = InputBox("Enter Participant 3, Trial 1 Score")
Range("D4").Select
ActiveCell.Value = InputBox("Enter Participant 3, Trial 2 Score")
Range("E4").Select
ActiveCell.Value = InputBox("Enter Participant 3, Trial 3 Score")
Range("F4").Select
ActiveCell.Value = InputBox("Enter Participant 3, Test Score")
'Range("B5").Select
'ActiveCell.Value = InputBox("Enter Participant 4 Name")
'Range("C5").Select
'ActiveCell.Value = InputBox("Enter Participant 4, Trial 1 Score")
'Range("D5").Select
'ActiveCell.Value = InputBox("Enter Participant 4, Trial 2 Score")
'Range("E5").Select
'ActiveCell.Value = InputBox("Enter Participant 4, Trial 3 Score")
'Range("F5").Select
'ActiveCell.Value = InputBox("Enter Participant 4, Test Score")
'Range("B6").Select
'ActiveCell.Value = InputBox("Enter Participant 5 Name")
'Range("C6").Select
'ActiveCell.Value = InputBox("Enter Participant 5, Trial 1 Score")
'Range("D6").Select
'ActiveCell.Value = InputBox("Enter Participant 5, Trial 2 Score")
'Range("E6").Select
'ActiveCell.Value = InputBox("Enter Participant 5, Trial 3 Score")
'Range("F6").Select
'ActiveCell.Value = InputBox("Enter Participant 5, Test Score")
'Range("B7").Select
'ActiveCell.Value = InputBox("Enter Participant 6 Name")
'Range("C7").Select
'ActiveCell.Value = InputBox("Enter Participant 6, Trial 1 Score")
'Range("D7").Select
'ActiveCell.Value = InputBox("Enter Participant 6, Trial 2 Score")
'Range("E7").Select
'ActiveCell.Value = InputBox("Enter Participant 6, Trial 3 Score")
'Range("F7").Select
'ActiveCell.Value = InputBox("Enter Participant 6, Test Score")
'Range("B8").Select
'ActiveCell.Value = InputBox("Enter Participant 7 Name")
'Range("C8").Select
'ActiveCell.Value = InputBox("Enter Participant 7, Trial 1 Score")
'Range("D8").Select
'ActiveCell.Value = InputBox("Enter Participant 7, Trial 2 Score")
'Range("E8").Select
'ActiveCell.Value = InputBox("Enter Participant 7, Trial 3 Score")
'Range("F8").Select
'ActiveCell.Value = InputBox("Enter Participant 7, Test Score")
'Range("B9").Select
'ActiveCell.Value = InputBox("Enter Participant 8 Name")
'Range("C9").Select
'ActiveCell.Value = InputBox("Enter Participant 8, Trial 1 Score")
'Range("D9").Select
'ActiveCell.Value = InputBox("Enter Participant 8, Trial 2 Score")
'Range("E9").Select
'ActiveCell.Value = InputBox("Enter Participant 8, Trial 3 Score")
'Range("F9").Select
'ActiveCell.Value = InputBox("Enter Participant 8, Test Score")
'Range("B10").Select
'ActiveCell.Value = InputBox("Enter Participant 9 Name")
'Range("C10").Select
'ActiveCell.Value = InputBox("Enter Participant 9, Trial 1 Score")
'Range("D10").Select
'ActiveCell.Value = InputBox("Enter Participant 9, Trial 2 Score")
'Range("E10").Select
'ActiveCell.Value = InputBox("Enter Participant 9, Trial 3 Score")
'Range("F10").Select
'ActiveCell.Value = InputBox("Enter Participant 9, Test Score")
'Range("B11").Select
'ActiveCell.Value = InputBox("Enter Participant 10 Name")
'Range("C11").Select
'ActiveCell.Value = InputBox("Enter Participant 10, Trial 1 Score")
'Range("D11").Select
'ActiveCell.Value = InputBox("Enter Participant 10, Trial 2 Score")
'Range("E11").Select
'ActiveCell.Value = InputBox("Enter Participant 10, Trial 3 Score")
'Range("F11").Select
'ActiveCell.Value = InputBox("Enter Participant 10, Test Score")
'Range("B12").Select
'ActiveCell.Value = InputBox("Enter Participant 11 Name")
'Range("C12").Select
'ActiveCell.Value = InputBox("Enter Participant 11, Trial 1 Score")
'Range("D12").Select
'ActiveCell.Value = InputBox("Enter Participant 11, Trial 2 Score")
'Range("E12").Select
'ActiveCell.Value = InputBox("Enter Participant 11, Trial 3 Score")
'Range("F12").Select
'ActiveCell.Value = InputBox("Enter Participant 11, Test Score")
'Range("B13").Select
'ActiveCell.Value = InputBox("Enter Participant 12 Name")
'Range("C13").Select
'ActiveCell.Value = InputBox("Enter Participant 12, Trial 1 Score")
'Range("D13").Select
'ActiveCell.Value = InputBox("Enter Participant 12, Trial 2 Score")
'Range("E13").Select
'ActiveCell.Value = InputBox("Enter Participant 12, Trial 3 Score")
'Range("F13").Select
'ActiveCell.Value = InputBox("Enter Participant 12, Test Score")
Range("C15").Select
ActiveCell.Formula = "=MEDIAN(C2:C13)"
Range("C16").Select
ActiveCell.Formula = "=PERCENTILE.INC(C2:C13,0.75)-PERCENTILE.INC(C2:C13,0.25)"
Range("D15").Select
ActiveCell.Formula = "=MEDIAN(D2:D13)"
Range("D16").Select
ActiveCell.Formula = "=PERCENTILE.INC(D2:D13,0.75)-PERCENTILE.INC(D2:D13,0.25)"
Range("E15").Select
ActiveCell.Formula = "=MEDIAN(E2:E13)"
Range("E16").Select
ActiveCell.Formula = "=PERCENTILE.INC(E2:E13,0.75)-PERCENTILE.INC(E2:E13,0.25)"
Range("F15").Select
ActiveCell.Formula = "=MEDIAN(F2:F13)"
Range("F16").Select
ActiveCell.Formula = "=PERCENTILE.INC(F2:F13,0.75)-PERCENTILE.INC(F2:F13,0.25)"
'Range("C19").Select
'ActiveCell.Value = InputBox("Enter Course Median for Trial 1")
'Range("D19").Select
'ActiveCell.Value = InputBox("Enter Course Median for Trial 2")
'Range("E19").Select
'ActiveCell.Value = InputBox("Enter Course Median for Trial 3")
'Range("F19").Select
'ActiveCell.Value = InputBox("Enter Course Median for Testing Station")
'Range("C20").Select
'ActiveCell.Value = InputBox("Enter Course Interquartile Range (IQR) for Trial 1")
'Range("D20").Select
'ActiveCell.Value = InputBox("Enter Course Interquartile Range (IQR) for Trial 2")
'Range("E20").Select
'ActiveCell.Value = InputBox("Enter Course Interquartile Range (IQR) for Trial 3")
'Range("F20").Select
'ActiveCell.Value = InputBox("Enter Course Interquartile Range (IQR) for Testing Station")
' Declare the Range of variables to be plotted
Dim Labels As Range
Set Labels = Range("B1:F1")
Dim UsrRng As Range
Set UsrRng = Range("B2:F2")
Dim ClassMedians As Range
Set ClassMedians = Range("B15:F15")
Dim CourseMedians As Range
Set CourseMedians = Range("B19:F19")
Dim myDataRange As Range
Set myDataRange = Application.InputBox( _
Prompt:="Specify the cell range [e.g. Bx:Fy] of the participant you want graphed.", _
Title:="Select a Range of Participant Data", Type:=8)
Dim myChart As ChartObject
With myChart
' Create Bar Chart ("Clustered Column Chart") of Results
Range("B1:F1, & myDataRange, B15:F15, B19:F19").Select
Range("B19").Activate
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlColumnClustered
ActiveChart.SetSourceData Source:=Range( _
"B1:F1, & myDataRange, B15:F15, B19:F19")
End With
ActiveWorkbook.SaveAs Filename:="practical_simulation_report_example.xlsm"
End Sub
ID | Participant | Trial 1 | Trial 2 | Trial 3 | Test |
1 | Harle | 8 | 9 | 10 | 10 |
2 | Gilbert | 4 | 4 | 4 | 4 |
3 | Cochran | 6 | 7 | 8 | 9 |
4 | 4 | 4 | 4 | 4 | |
5 | 5 | 5 | 5 | 5 | |
6 | 6 | 6 | 6 | 6 | |
7 | 7 | 7 | 7 | 7 | |
8 | 8 | 8 | 8 | 8 | |
9 | 8 | 8 | 8 | 8 | |
10 | 9 | 9 | 9 | 9 | |
11 | 10 | 10 | 10 | 10 | |
12 | 10 | 10 | 10 | 10 | 10 |
Class Median | 7.5 | 7.5 | 8 | 8 | |
Class IQR | 2.5 | 3.25 | 3.5 | 3.5 | |
Course Median | 5 | 8 | 9 | 10 | |
Course IQR | 4.5 | 3.1 | 2.7 | 0.9 |
<tbody>
</tbody>
================= CUT HERE FOR CODE ==================
Public Sub Graph1()
Range("B2").Select
ActiveCell.Value = InputBox("Enter Participant 1 Name")
Range("C2").Select
ActiveCell.Value = InputBox("Enter Participant 1, Trial 1 Score")
Range("D2").Select
ActiveCell.Value = InputBox("Enter Participant 1, Trial 2 Score")
Range("E2").Select
ActiveCell.Value = InputBox("Enter Participant 1, Trial 3 Score")
Range("F2").Select
ActiveCell.Value = InputBox("Enter Participant 1, Test Score")
Range("B3").Select
ActiveCell.Value = InputBox("Enter Participant 2 Name")
Range("C3").Select
ActiveCell.Value = InputBox("Enter Participant 2 Trial 1 Score")
Range("D3").Select
ActiveCell.Value = InputBox("Enter Participant 2, Trial 2 Score")
Range("E3").Select
ActiveCell.Value = InputBox("Enter Participant 2, Trial 3 Score")
Range("F3").Select
ActiveCell.Value = InputBox("Enter Participant 2, Test Score")
Range("B4").Select
ActiveCell.Value = InputBox("Enter Participant 3 Name")
Range("C4").Select
ActiveCell.Value = InputBox("Enter Participant 3, Trial 1 Score")
Range("D4").Select
ActiveCell.Value = InputBox("Enter Participant 3, Trial 2 Score")
Range("E4").Select
ActiveCell.Value = InputBox("Enter Participant 3, Trial 3 Score")
Range("F4").Select
ActiveCell.Value = InputBox("Enter Participant 3, Test Score")
'Range("B5").Select
'ActiveCell.Value = InputBox("Enter Participant 4 Name")
'Range("C5").Select
'ActiveCell.Value = InputBox("Enter Participant 4, Trial 1 Score")
'Range("D5").Select
'ActiveCell.Value = InputBox("Enter Participant 4, Trial 2 Score")
'Range("E5").Select
'ActiveCell.Value = InputBox("Enter Participant 4, Trial 3 Score")
'Range("F5").Select
'ActiveCell.Value = InputBox("Enter Participant 4, Test Score")
'Range("B6").Select
'ActiveCell.Value = InputBox("Enter Participant 5 Name")
'Range("C6").Select
'ActiveCell.Value = InputBox("Enter Participant 5, Trial 1 Score")
'Range("D6").Select
'ActiveCell.Value = InputBox("Enter Participant 5, Trial 2 Score")
'Range("E6").Select
'ActiveCell.Value = InputBox("Enter Participant 5, Trial 3 Score")
'Range("F6").Select
'ActiveCell.Value = InputBox("Enter Participant 5, Test Score")
'Range("B7").Select
'ActiveCell.Value = InputBox("Enter Participant 6 Name")
'Range("C7").Select
'ActiveCell.Value = InputBox("Enter Participant 6, Trial 1 Score")
'Range("D7").Select
'ActiveCell.Value = InputBox("Enter Participant 6, Trial 2 Score")
'Range("E7").Select
'ActiveCell.Value = InputBox("Enter Participant 6, Trial 3 Score")
'Range("F7").Select
'ActiveCell.Value = InputBox("Enter Participant 6, Test Score")
'Range("B8").Select
'ActiveCell.Value = InputBox("Enter Participant 7 Name")
'Range("C8").Select
'ActiveCell.Value = InputBox("Enter Participant 7, Trial 1 Score")
'Range("D8").Select
'ActiveCell.Value = InputBox("Enter Participant 7, Trial 2 Score")
'Range("E8").Select
'ActiveCell.Value = InputBox("Enter Participant 7, Trial 3 Score")
'Range("F8").Select
'ActiveCell.Value = InputBox("Enter Participant 7, Test Score")
'Range("B9").Select
'ActiveCell.Value = InputBox("Enter Participant 8 Name")
'Range("C9").Select
'ActiveCell.Value = InputBox("Enter Participant 8, Trial 1 Score")
'Range("D9").Select
'ActiveCell.Value = InputBox("Enter Participant 8, Trial 2 Score")
'Range("E9").Select
'ActiveCell.Value = InputBox("Enter Participant 8, Trial 3 Score")
'Range("F9").Select
'ActiveCell.Value = InputBox("Enter Participant 8, Test Score")
'Range("B10").Select
'ActiveCell.Value = InputBox("Enter Participant 9 Name")
'Range("C10").Select
'ActiveCell.Value = InputBox("Enter Participant 9, Trial 1 Score")
'Range("D10").Select
'ActiveCell.Value = InputBox("Enter Participant 9, Trial 2 Score")
'Range("E10").Select
'ActiveCell.Value = InputBox("Enter Participant 9, Trial 3 Score")
'Range("F10").Select
'ActiveCell.Value = InputBox("Enter Participant 9, Test Score")
'Range("B11").Select
'ActiveCell.Value = InputBox("Enter Participant 10 Name")
'Range("C11").Select
'ActiveCell.Value = InputBox("Enter Participant 10, Trial 1 Score")
'Range("D11").Select
'ActiveCell.Value = InputBox("Enter Participant 10, Trial 2 Score")
'Range("E11").Select
'ActiveCell.Value = InputBox("Enter Participant 10, Trial 3 Score")
'Range("F11").Select
'ActiveCell.Value = InputBox("Enter Participant 10, Test Score")
'Range("B12").Select
'ActiveCell.Value = InputBox("Enter Participant 11 Name")
'Range("C12").Select
'ActiveCell.Value = InputBox("Enter Participant 11, Trial 1 Score")
'Range("D12").Select
'ActiveCell.Value = InputBox("Enter Participant 11, Trial 2 Score")
'Range("E12").Select
'ActiveCell.Value = InputBox("Enter Participant 11, Trial 3 Score")
'Range("F12").Select
'ActiveCell.Value = InputBox("Enter Participant 11, Test Score")
'Range("B13").Select
'ActiveCell.Value = InputBox("Enter Participant 12 Name")
'Range("C13").Select
'ActiveCell.Value = InputBox("Enter Participant 12, Trial 1 Score")
'Range("D13").Select
'ActiveCell.Value = InputBox("Enter Participant 12, Trial 2 Score")
'Range("E13").Select
'ActiveCell.Value = InputBox("Enter Participant 12, Trial 3 Score")
'Range("F13").Select
'ActiveCell.Value = InputBox("Enter Participant 12, Test Score")
Range("C15").Select
ActiveCell.Formula = "=MEDIAN(C2:C13)"
Range("C16").Select
ActiveCell.Formula = "=PERCENTILE.INC(C2:C13,0.75)-PERCENTILE.INC(C2:C13,0.25)"
Range("D15").Select
ActiveCell.Formula = "=MEDIAN(D2:D13)"
Range("D16").Select
ActiveCell.Formula = "=PERCENTILE.INC(D2:D13,0.75)-PERCENTILE.INC(D2:D13,0.25)"
Range("E15").Select
ActiveCell.Formula = "=MEDIAN(E2:E13)"
Range("E16").Select
ActiveCell.Formula = "=PERCENTILE.INC(E2:E13,0.75)-PERCENTILE.INC(E2:E13,0.25)"
Range("F15").Select
ActiveCell.Formula = "=MEDIAN(F2:F13)"
Range("F16").Select
ActiveCell.Formula = "=PERCENTILE.INC(F2:F13,0.75)-PERCENTILE.INC(F2:F13,0.25)"
'Range("C19").Select
'ActiveCell.Value = InputBox("Enter Course Median for Trial 1")
'Range("D19").Select
'ActiveCell.Value = InputBox("Enter Course Median for Trial 2")
'Range("E19").Select
'ActiveCell.Value = InputBox("Enter Course Median for Trial 3")
'Range("F19").Select
'ActiveCell.Value = InputBox("Enter Course Median for Testing Station")
'Range("C20").Select
'ActiveCell.Value = InputBox("Enter Course Interquartile Range (IQR) for Trial 1")
'Range("D20").Select
'ActiveCell.Value = InputBox("Enter Course Interquartile Range (IQR) for Trial 2")
'Range("E20").Select
'ActiveCell.Value = InputBox("Enter Course Interquartile Range (IQR) for Trial 3")
'Range("F20").Select
'ActiveCell.Value = InputBox("Enter Course Interquartile Range (IQR) for Testing Station")
' Declare the Range of variables to be plotted
Dim Labels As Range
Set Labels = Range("B1:F1")
Dim UsrRng As Range
Set UsrRng = Range("B2:F2")
Dim ClassMedians As Range
Set ClassMedians = Range("B15:F15")
Dim CourseMedians As Range
Set CourseMedians = Range("B19:F19")
Dim myDataRange As Range
Set myDataRange = Application.InputBox( _
Prompt:="Specify the cell range [e.g. Bx:Fy] of the participant you want graphed.", _
Title:="Select a Range of Participant Data", Type:=8)
Dim myChart As ChartObject
With myChart
' Create Bar Chart ("Clustered Column Chart") of Results
Range("B1:F1, & myDataRange, B15:F15, B19:F19").Select
Range("B19").Activate
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlColumnClustered
ActiveChart.SetSourceData Source:=Range( _
"B1:F1, & myDataRange, B15:F15, B19:F19")
End With
ActiveWorkbook.SaveAs Filename:="practical_simulation_report_example.xlsm"
End Sub