Sub x()
Dim nMinAP As Long, nMaxAP As Long, nStepAP As Long
Dim nMinAG As Long, nMaxAG As Long, nStepAG As Long
Dim i As Long, nLastcol As Long, nlastrow As Long
Dim rRow, rCol, rRef, j As Long
Dim rStart As Range, rData As Range
With Application
.EnableEvents = False
.ScreenUpdating = False
.DisplayAlerts = False
.Calculation = xlCalculationManual
End With
On Error Resume Next
Sheets("Charts").Delete
On Error GoTo 0
Sheets.Add(After:=Sheets(Sheets.Count)).Name = "Charts"
Sheets("Mov_Avg_Chart").Activate
nMinAP = Range("B22").Value
nMaxAP = Range("B23").Value
nStepAP = Range("B24").Value
nMinAG = Range("B25").Value
nMaxAG = Range("B26").Value
nStepAG = Range("B27").Value
Set rRow = Range("C8")
Set rCol = Range("C6")
rRef = Array("G7", "G9", "G10", "G11")
nlastrow = Cells.Find(What:="*", After:=Cells(1, 1), SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
nLastcol = Cells.Find(What:="*", After:=Cells(1, 1), SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
If nLastcol < 9 Then
Range(Cells(15, "I"), Cells(nlastrow, "I")).Clear
Else
Range(Cells(15, "I"), Cells(nlastrow, nLastcol)).Clear
End If
Set rStart = Range("I15")
For i = LBound(rRef) To UBound(rRef)
With rStart
.Formula = "=" & rRef(i)
.Interior.ColorIndex = 4
.Offset(1).Value = nMinAP
.Offset(1).DataSeries Rowcol:=xlColumns, Type:=xlLinear, Step:=nStepAP, Stop:=nMaxAP
.Offset(, 1).Value = nMinAG
.Offset(, 1).DataSeries Rowcol:=xlRows, Type:=xlLinear, Step:=nStepAG, Stop:=nMaxAG
With .CurrentRegion
.Rows(1).Font.Bold = True
.Columns(1).Font.Bold = True
End With
End With
Set rData = rStart.Offset(1, 1).CurrentRegion
With rData
.NumberFormat = "0.00"
.Table RowInput:=rRow, ColumnInput:=rCol
With .Offset(1, 1).Resize(.Rows.Count - 1, .Columns.Count - 1)
.Select
ActiveSheet.Shapes.AddChart.Select
ActiveChart.SetSourceData Source:=Range("Mov_Avg_Chart!" & .Address)
ActiveChart.ChartType = xlSurfaceTopView
ActiveChart.Location xlLocationAsObject, "Charts"
For j = 1 To rData.Rows.Count - 1
ActiveChart.SeriesCollection(j).Name = rData(j + 1, 1)
Next j
ActiveChart.SeriesCollection(1).XValues = rData(1, 2).Resize(, rData.Columns.Count - 1)
Sheets("Mov_Avg_Chart").Activate
End With
End With
Set rStart = rStart.Offset(rStart.CurrentRegion.Rows.Count + 1)
Next i
With Application
.EnableEvents = True
.ScreenUpdating = True
.DisplayAlerts = True
.Calculation = xlCalculationAutomatic
End With
End Sub
Bookmarks