## Scatter Plot Woes

Register for a FREE account, and/
or Log in to avoid these ads!

Hello All,

New here, and somewhat new to excel and VBA. I am having some hard time learning from template examples of scatter plots and was wondering if anybody would be nice enough to help me?

I have a worksheet with 2 pages, a cover page and a data page (to which raw data is imported, naturally).
There is a button on the cover which goes through a column on the cover next to a given set of parameters to see if there is a Y next to it, if so it extrapolates data from the data sheet posts it in a new sheet with the Parameter name and then creates a simple scatter plot for it in that new sheet. The problem I am having is that I must also plot the standard deviation *2 and *(-2) on the same chart as well as the mean. If anybody can help me with this it would be greatly appreciated. Here is what I have so far:

Private Sub CommandButton2_Click()

'Set Cover sheet to actice workbook sheet
ActiveWorkbook.Sheets("Cover").Activate

'Dimension and set Graphs array to range
Dim Graphs() As Variant
Graphs = Range("J2:J32")
Dim TempData(1 To 93) As Variant
Dim STDEVData(1 To 93) As Variant
Dim Mean As Integer
Dim STDEV As Integer
Dim TempMean As Long

'Iterate through Graphs array

For i = 1 To 30

If Graphs(i, 1) = "Y" Then

'Create new sheet and name it the parameter of the graph and add data values
Parameter = Sheets("DATA").Range("A" & i + 1).Value
Worksheets.Add(After:=Worksheets(2)).Name = Parameter

'imports X & Y axis data into Worksheet
For x = 1 To 93
Sheets(Parameter).Range("B" & x).Value = Sheets("DATA").Range("H" & i + 1).Offset(0, x - 1).Value
Sheets(Parameter).Range("A" & x).Value = x
TempMean = TempMean + ((Sheets("DATA").Range("H" & i + 1).Offset(0, x - 1).Value) - Mean) ^ 2

Next x

'Calculates mean, stdev, lower and upper limits
Mean = Sheets("DATA").Range("D" & i + 1).Value
STDEV = Sqr(TempMean / 93)
UL = STDEV * 2
LL = STDEV * (-2)

'Plots graph on open WS

GRange = Parameter & "!\$B\$1:\$B\$93"
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlXYScatter
ActiveChart.SetSourceData Source:=ActiveSheet.Range("B1:B93")

End If
Next i