sub STDEV()
dim lrow, lcol as long
With sheets1
lRow = .Cells(Rows.Count, 13).End(xlUp).Row 'Last row Column M=20
lCol = .Cells(1, Columns.Count).End(xlToLeft).Column 'Last column in row 1
If lCol < 14 Then lCol = 14
.Range(.Cells(2, "N"), .Cells(lRow, lCol)).Clear
.Range("I3:L" & lRow).Clear
.Columns("D:H").ClearContents
.Columns("M").ClearContents
.Range("H1:M1").Value = Array("CONFIDENCE", "SUM", "MAX", "MIN", "Average", "STDEV.P")
.Range("I3:I" & lRow).FormulaR1C1 = "=round(Sum(RC14:RC" & lCol & "),0)"
.Range("J3:J" & lRow).FormulaR1C1 = "=max(RC14:RC" & lCol & ")"
.Range("K3:K" & lRow).FormulaR1C1 = "=min(RC14:RC" & lCol & ")"
.Range("L3:L" & lRow).FormulaR1C1 = "=iferror(AVERAGE(RC14:RC" & lCol & "),0)"
.Range("M3:M" & lRow).FormulaR1C1 = "=round(STDEV.P(RC14:RC" & lCol & "),0)"
.Range("H3:H" & lRow).FormulaR1C1 = "=round(CONFIDENCE(0.05,RC13," & lCol - 13 & "),0)"
.Range("H2", .Cells(lRow, lCol)).Value = .Range("H2", .Cells(lRow, lCol)).Value
.Range("H2", .Cells(lRow, lCol)).NumberFormat = "#,##0"
.Rows(1).Font.Bold = True
With .UsedRange.Borders '.Range(.Cells(1, 1), .Cells(lRow, lCol - 5)).Borders
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End With
End sub