```
Sub Bell_Chart()
'initializations
Pi = Evaluate("Pi()")
Ac = 0
RW = 4
'obtain variation estimate (for the example is Moving Range estimate) and data's average
Do
Ac = Ac + Abs(Cells(RW, 2) - Cells(RW - 1, 2))
RW = RW + 1
Loop Until Cells(RW, 2) = ""
RowCount = RW - 3
Xbarbar = Evaluate("Average(B3:B" & RowCount + 2 & ")")
StdDev_within = Ac / (RowCount - 1) / 1.128
'obtain the limits for the bell shape, the X where the accumulated norm dist is 0.001 and 0.999
Min = Evaluate("NORMINV(0.001," & Xbarbar & "," & StdDev_within & ")")
Max = Evaluate("NORMINV(0.999," & Xbarbar & "," & StdDev_within & ")")
'so, I have the Min and Max of the chart, but if the data has values beyond these values, adjust the chart limits
If Min > Cells(4, 5) Then Min = Cells(4, 5)
If Max < Cells(5, 5) Then Max = Cells(5, 5)
Ac = (Max - Min) / 10
'and add a little something so the chart won't be touching the borderline (the limits of the chart)
Min = Min - Ac: Max = Max + Ac
'calculate the Cpk (for moving range), this wasn't in the original code, but it's nice, if you put the LSL in cell(4,5) and USL in cell(5,5)
Cells(6, 5) = (Xbarbar - Cells(4, 5)) / (3 * StdDev_within)
Ac = (Cells(5, 5) - Xbarbar) / (3 * StdDev_within)
If Cells(6, 5) > Ac Then Cells(6, 5) = Ac
'a difference against the posted code, I will always take 100 data points to make the chart
x = Min
c8 = (Max - Min) / 100
For RW = 15 To 115
'you can use the commented equation insteed, like Steve said, but I used yours with a slight change
'Sheets("Data").Cells(RW, 14) = Evaluate("NormDist(" & x & "," & Xbarbar & "," & StdDev_within & ",false)")
Sheets("Data").Cells(RW, 14) = (1 / (StdDev_within * (2 * Pi) ^ 0.5)) * Exp(-((x - Xbarbar) / StdDev_within) ^ 2 / 2)
Sheets("Data").Cells(RW, 15) = x
'I added the next 2 instructions for charting the LSL and USL
Sheets("Data").Cells(RW, 16) = Cells(4, 5)
Sheets("Data").Cells(RW, 17) = Cells(5, 5)
x = x + c8
Next RW
'this doesn't need to be done always, but once done it will make the charting more easily, insteed of ranges defined on the chart can be their names.
Sheets("Data").Range(Sheets("Data").Cells(15, 14), Sheets("Data").Cells(115, 14)).Name = "X_Values"
Sheets("Data").Range(Sheets("Data").Cells(15, 15), Sheets("Data").Cells(115, 15)).Name = "Bell"
Sheets("Data").Range(Sheets("Data").Cells(15, 16), Sheets("Data").Cells(115, 16)).Name = "LSL"
Sheets("Data").Range(Sheets("Data").Cells(15, 17), Sheets("Data").Cells(115, 17)).Name = "USL"
End Sub
```