SnyperBunny
New Member
- Joined
- Jan 21, 2013
- Messages
- 23
Hi, I've written a vba code to graph a large number of graphs for me with two data series on each graph. To test my theory on it working I broke it down into parts and ran each seperately as I went so I wouldnt have to sift through the whole thing to find an issue when I was finally finished... well I'm finished and it has a random error that for the life of me I cannot spot... If someone could please help me find what is causing this error I would be SO grateful! 

Code:
Sub chart()
Dim n As Integer 'worksheet index number that the chart goes on
Dim date_col As String
Dim m_max As String
Dim m_min As String
Dim m_avg As String
Dim a_max As String
Dim a_min As String
Dim a_avg As String
Dim k As Integer
'n = 3
date_col = "A"
m_max = "C"
m_min = "G"
m_avg = "E"
a_max = "B"
a_min = "F"
a_avg = "D"
For k = 1 To 10 Step 1
n = k + 3
'Maximum Temperature
ThisWorkbook.Worksheets(n).Shapes.AddChart.Select
ActiveChart.ChartType = xlXYScatterLines
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(1).Name = "Actual Max"
ActiveChart.SeriesCollection(1).XValues = Worksheets(2).Range(date_col & "3:" & date_col & "122")
ActiveChart.SeriesCollection(1).Values = Worksheets(2).Range(a_max & "3:" & a_max & "122")
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(2).Name = "Model Max"
ActiveChart.SeriesCollection(2).XValues = Worksheets(2).Range(date_col & "3:" & date_col & "122")
ActiveChart.SeriesCollection(2).Values = Worksheets(2).Range(m_max & "3:" & m_max & "122")
[COLOR=#008000]I stuck a end sub here for the sake of trying to isolate the part throwing the error and it still came when I ran the top part. :( This is especially confusing since I ran it just a few minutes ago as I was testing the pieces I wrote as I was writing it and ran just fine with no errors. I have absolutely no idea what is going wrong.... [/COLOR]
'Average Temperature
Worksheets(n).Shapes.AddChart.Select
ActiveChart.ChartType = xlXYScatterLines
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(1).Name = "Actual Average"
ActiveChart.SeriesCollection(1).XValues = Worksheets(2).Range(date_col & "3:" & date_col & "122")
ActiveChart.SeriesCollection(1).Values = Worksheets(2).Range(a_avg & "3:" & a_avg & "122")
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(2).Name = "Model Average"
ActiveChart.SeriesCollection(2).XValues = Worksheets(2).Range(date_col & "3:" & date_col & "122")
ActiveChart.SeriesCollection(2).Values = Worksheets(2).Range(m_avg & "3:" & m_avg & "122")
'Minimum Temperature
Worksheets(n).Shapes.AddChart.Select
ActiveChart.ChartType = xlXYScatterLines
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(1).Name = "Actual Min"
ActiveChart.SeriesCollection(1).XValues = Worksheets(2).Range(date_col & "3:" & date_col & "122")
ActiveChart.SeriesCollection(1).Values = Worksheets(2).Range(a_min & "3:" & a_min & "122")
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(2).Name = "Model Min"
ActiveChart.SeriesCollection(2).XValues = Worksheets(2).Range(date_col & "3:" & date_col & "122")
ActiveChart.SeriesCollection(2).Values = Worksheets(2).Range(m_min & "3:" & m_min & "122")
m_max = Chr(Asc(m_max) + 7)
m_min = Chr(Asc(m_min) + 7)
m_avg = Chr(Asc(m_avg) + 7)
a_max = Chr(Asc(a_max) + 7)
a_min = Chr(Asc(a_min) + 7)
a_avg = Chr(Asc(a_avg) + 7)
date_col = Chr(Asc(date_col) + 7)
'n = n + 1
Next k
'loop
End Sub