I'm trying to redefine the 3 series of an embedded chart. At first, I did it without the use of a chart class. It worked most of the time time, but not always. So, thought I was missing something and tried to do it with a chart class.
Created a class module, named it PHChartClass. Entered the following code (yes, some routines are missing for sake of brevity):
Option Explicit
Option Compare Text
Public WithEvents PHChartClass As Chart
Private PHChart As Chart
Public Sub MoveSeries
Dim CPIRow
Dim DateRow
Dim theDates As Range
Dim DataSheet As Worksheet
Dim OldestMonth As Range
Dim NewestMonth As Range
Dim QCWindow As Range
Dim DateWindow As Range
Dim DataWindow As Range
CPIRow = Range("CPIData"
.Row
DateRow = Range("Date"
.Row
Set theDates = Range("Date"![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
Set DataSheet = Sheets("Data"![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
Set QCWindow = Sheets("QC"
.Range("TheWindow"![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
'Find the Oldest date in theDates
Set OldestMonth = FindOldestDate(QCWindow)
Set OldestMonth = LookupDate(OldestMonth.Value, DataSheet, DataSheet.Range("Date"
)
If OldestMonth Is Nothing Then
MsgBox "Error updating PH chart"
GoTo Cleanup
End If
'Find the newest date in theDates
Set NewestMonth = FindNewestDate(QCWindow, DataSheet, OldestMonth.Column)
If IsEmpty(NewestMonth.Value) Then
'at the end of the visible list.
Exit Sub
End If
'Create a DateWindow that points to 6 columns of dates on the Data sheet
Set DateWindow = DataSheet.Range(OldestMonth.Address, NewestMonth.Address)
Set DataWindow = DateWindow.Offset(Sheets("Data"
.Range("CPIData"
.Row - 1)
PHChart.Activate Here is the problem. Object variable or with variable not set
'Set range for CPI
PHChart.SeriesCollection("CPI"
.Values = DataWindow
'Set Range for SPI
Set DataWindow = DateWindow.Offset(Sheets("Data"
.Range("SPIData"
.Row - 1)
PHChart.SeriesCollection("SPI"
.Values = DataWindow
'Set Range for BAC/EAC4
Set DataWindow = DateWindow.Offset(Sheets("Data"
.Range("BACEAC4"
.Row - 1)
PHChart.SeriesCollection("BAC/EAC4"
.Values = DataWindow
'Set Category labels
PHChart.SeriesCollection("BAC/EAC4"
.XValues = DateWindow
Sheets("QC"
.Range("h10"
.Select
Cleanup:
Set DataSheet = Nothing
Set QCWindow = Nothing
Set OldestMonth = Nothing
Set NewestMonth = Nothing
End Sub
------------
What am I doing wrong?
Any help greatly appreciated!
Andrea
Created a class module, named it PHChartClass. Entered the following code (yes, some routines are missing for sake of brevity):
Option Explicit
Option Compare Text
Public WithEvents PHChartClass As Chart
Private PHChart As Chart
Public Sub MoveSeries
Dim CPIRow
Dim DateRow
Dim theDates As Range
Dim DataSheet As Worksheet
Dim OldestMonth As Range
Dim NewestMonth As Range
Dim QCWindow As Range
Dim DateWindow As Range
Dim DataWindow As Range
CPIRow = Range("CPIData"
DateRow = Range("Date"
Set theDates = Range("Date"
Set DataSheet = Sheets("Data"
Set QCWindow = Sheets("QC"
'Find the Oldest date in theDates
Set OldestMonth = FindOldestDate(QCWindow)
Set OldestMonth = LookupDate(OldestMonth.Value, DataSheet, DataSheet.Range("Date"
If OldestMonth Is Nothing Then
MsgBox "Error updating PH chart"
GoTo Cleanup
End If
'Find the newest date in theDates
Set NewestMonth = FindNewestDate(QCWindow, DataSheet, OldestMonth.Column)
If IsEmpty(NewestMonth.Value) Then
'at the end of the visible list.
Exit Sub
End If
'Create a DateWindow that points to 6 columns of dates on the Data sheet
Set DateWindow = DataSheet.Range(OldestMonth.Address, NewestMonth.Address)
Set DataWindow = DateWindow.Offset(Sheets("Data"
PHChart.Activate Here is the problem. Object variable or with variable not set
'Set range for CPI
PHChart.SeriesCollection("CPI"
'Set Range for SPI
Set DataWindow = DateWindow.Offset(Sheets("Data"
PHChart.SeriesCollection("SPI"
'Set Range for BAC/EAC4
Set DataWindow = DateWindow.Offset(Sheets("Data"
PHChart.SeriesCollection("BAC/EAC4"
'Set Category labels
PHChart.SeriesCollection("BAC/EAC4"
Sheets("QC"
Cleanup:
Set DataSheet = Nothing
Set QCWindow = Nothing
Set OldestMonth = Nothing
Set NewestMonth = Nothing
End Sub
------------
What am I doing wrong?
Any help greatly appreciated!
Andrea