The problem is that when you add the chart it tries to populate it with data in the current region.
This causes the operation to fail.
Move the active cell to an empty region
Sub Macro9()
'
Range("A1").Select
Set FindRng = ActiveSheet.UsedRange
With FindRng
Set c = ActiveSheet.UsedRange.Find(What:="AAAA", After:=FindRng.Cells(1, 1), LookIn:=xlValues, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
If Not c Is Nothing Then
First = c.Address
On Error Resume Next
Set Rng = c
Do
Set Rng = Union(Rng, c)
Set c = ActiveSheet.UsedRange.FindNext(c)
Loop While Not c Is Nothing And c.Address <> First
End If
End With
Rng.Select
LastCol3 = Selection.Count
With ActiveSheet
LastRow = Range("A1048576").End(xlUp).Row
Range("A5").Select
LastRow2 = Range(Selection, Selection.End(xlDown)).Count
Set Rngx = .Range("A6:A" & LastRow)
End With
Range("A1").Select
Cells.Find(What:="RunTime", After:=ActiveCell, LookIn:=xlValues, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
ActiveCell.Offset(1, 1).Select
'Do Until ActiveCell.Offset(-1, 0) = ""
If Not ActiveCell = "" Then
Set rngAc = ActiveCell
Range("A1000").Activate
Set chtTemp = ActiveSheet.Shapes.AddChart(xlXYScatterSmoothNoMarkers, Left:=100, Width:=550, Top:=75, Height:=325)
rngAc.Activate
With chtTemp
Set a = Selection
For x = 1 To LastCol3
Set Rngy = ActiveCell.Range("A1:A" & LastRow2 - 1)
.Chart.SeriesCollection.NewSeries
.Chart.SeriesCollection(x).XValues = Rngx
.Chart.SeriesCollection(x).Values = Rngy
.Chart.SeriesCollection(x).Name = ActiveCell.Offset(-5, 0)
.Chart.SeriesCollection(x).Format.Line.Weight = 1
.Chart.Axes(xlValue, xlPrimary).HasTitle = True
.Chart.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = ActiveCell.Offset(-1, 0)
.Chart.Axes(xlValue, xlPrimary).AxisTitle.Font.Size = 14
.Chart.Axes(xlValue, xlPrimary).AxisTitle.Font.Bold = True
.Chart.Axes(xlCategory, xlPrimary).HasTitle = True
.Chart.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Run Time (sec)"
.Chart.Axes(xlCategory, xlPrimary).AxisTitle.Font.Size = 14
.Chart.Axes(xlCategory, xlPrimary).AxisTitle.Font.Bold = True
.Chart.Legend.Font.Bold = True
.Chart.Legend.Font.Size = 12
.Chart.HasTitle = False
ActiveCell.Offset(0, 1).Select
Next x
End With
Else
ActiveCell.Offset(0, 1).Select
End If
'Loop
End Sub
Bookmarks