I am having some problems with one of my workbooks. The original file seems to work fine, but when I move it, sometimes I get Run-Time error '1004' some times I don't.
The problem arises when I try to change any of the .SeriesCollection values. In my workbook when I run my macro, it will fail at .SeriesCollection(1).Name = "10 Passes". Chart 2 already exists with 6 series' already defined. It seems that when I manualy go through and delete all the information out of each series (ie Right Click -> Source Data -> Series and delete name and set X and Y values to zero) the macro will run just fine.
Would it be best to:
1. Delete each series in each chart, then recreate them each time, or
2. Delete all the series information out of each SeriesCollection each time I run the macro?
Or is there some setting I need to change, or code to add to make it work correctly?
Sheets("Left Plot").Select
ActiveSheet.ChartObjects("Chart 2").Activate
ActiveChart.ChartArea.Select
With ActiveChart
' Beginning Profile
With .SeriesCollection(1)
.Name = "10 Passes"
.XValues = "='Position Data'!R1C4:R1C" & Samples + 3
.Values = "='Left Rut Data'!R" & LastRowLeft + 2 & "C4:R" & LastRowLeft + 2 & "C" & Samples + 3
End With
' Middle Profile
With .SeriesCollection(2)
.Name = Sheets("Data").Range("D" & MiddleRowLeft + 2).Value & " Passes"
.XValues = "='Position Data'!R" & MiddleRowLeft & "C4:R" & MiddleRowLeft & "C" & Samples + 3
.Values = "='Left Rut Data'!R" & LastRowLeft + 3 & "C4:R" & LastRowLeft + 3 & "C" & Samples + 3
End With
' Last Profile
With .SeriesCollection(3)
.Name = Sheets("Data").Range("D" & LastRowLeft + 2).Value & " Passes"
.XValues = "='Position Data'!R" & LastRowLeft & "C4:R" & LastRowLeft & "C" & Samples + 3
.Values = "='Left Rut Data'!R" & LastRowLeft + 4 & "C4:R" & LastRowLeft + 4 & "C" & Samples + 3
End With
' Max Location
With .SeriesCollection(4)
.Name = "Max Location"
.XValues = Array(MaxRutLeftPos, MaxRutLeftPos)
.Values = Array(-100, 20)
End With
' Sample Center
With .SeriesCollection(5)
.Name = "Sample Center"
.XValues = Array(SampleCenter, SampleCenter)
.Values = Array(-100, 20)
End With
' Averaged Distance
With .SeriesCollection(6)
.Name = "Averaged"
.XValues = Array(AvgEnd, AvgBegin)
.Values = Array(2.5, 2.5)
End With
End With
I am stumped. I fail to understand how it can work perfectly one minute, but when I move it, it fails. It should also be noted that I have no external links in my project.
Hope someone can help!
Thanks,
Eric
Bookmarks