Hi All,
Can anyone see what is wrong with this code? Series PT1 and PT2 update fine all the time but BAC always fails?
No errors are given, it just pops out of this function. No error handlers on. Verified that the named ranges are pointing to the correct places.
I'm at a loss.
Thanks in advance for any help/suggestions.
Andrea
Function MoveSeries()
'=======================================================
'=======================================================
'Range("Date"
is a row of dates on a Data Sheet
'
'FocusMonth is set elsewhere. In a 'window' of 6
'dates FocusMonth is the 4th month. Ex:
'Jan-02 Feb-02 Mar-02 Apr-02 May-02 Jun-02
'FocusMonth is Apr02 in this case. Anything after is
'in the future, before that, in the past. (e.g. Apr-02 is the current month reporting)
'These dates are pulled from Sheets("Health"
and
'any number of dates can exist.
'Pulling the dates from Sheets("Health"
into this window of 6
'allows it to act like a sliding window so it
'can slide backwards in time or look further ahead
'than the default 2 months and displays
'corresponding data from the Data sheet.
'Purpose of this procedure is to move series in a chart
'so that the data in the chart moves with the data
'as FocusMonth changes.
'=======================================================
'=======================================================
'Get the column of the oldest month - subtract
'3 because the oldest month is 3 months before
'the focus month
OldestMonthCol = WorksheetFunction.Match(FocusMonth, Range("Date"
, 0) - 3
'Since we always display 6 in the window, the newest
'month 5 more than Oldest
NewestMonthCol = OldestMonthCol + 5
ChartName = Worksheets("Quad Chart"
.ChartObjects(1).Name
ActiveSheet.ChartObjects(ChartName).Activate
Dim DataRange As Range
Dim WindowRange As Range
Dim DataSheet As Worksheet
Set DataSheet = Sheets("Data"![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
With DataSheet
'Create a "window" of 6 dates
Set WindowRange = .Range(.Cells(1, OldestMonthCol).Address, .Cells(1, NewestMonthCol).Address)
'Loop through all the series and change them
For i = 1 To ActiveChart.SeriesCollection.Count
Select Case i
Case 1
theRow = .Range("PT1"
.Row
theName = "PT1"
Case 2
theRow = .Range("PT2"
.Row
theName = "PT2"
Case 3
theRow = .Range("BAC"
.Row
theName = "BAC"
End Select
'set the range for the window of dates in view
Set DataRange = .Range(.Cells(theRow, OldestMonthCol).Address, .Cells(theRow, NewestMonthCol).Address)
ActiveChart.SeriesCollection(theName).XValues = WindowRange
ActiveChart.SeriesCollection(theName).Values = DataRange
Next i
End With
end function
Can anyone see what is wrong with this code? Series PT1 and PT2 update fine all the time but BAC always fails?
No errors are given, it just pops out of this function. No error handlers on. Verified that the named ranges are pointing to the correct places.
I'm at a loss.
Thanks in advance for any help/suggestions.
Andrea
Function MoveSeries()
'=======================================================
'=======================================================
'Range("Date"
'
'FocusMonth is set elsewhere. In a 'window' of 6
'dates FocusMonth is the 4th month. Ex:
'Jan-02 Feb-02 Mar-02 Apr-02 May-02 Jun-02
'FocusMonth is Apr02 in this case. Anything after is
'in the future, before that, in the past. (e.g. Apr-02 is the current month reporting)
'These dates are pulled from Sheets("Health"
'any number of dates can exist.
'Pulling the dates from Sheets("Health"
'allows it to act like a sliding window so it
'can slide backwards in time or look further ahead
'than the default 2 months and displays
'corresponding data from the Data sheet.
'Purpose of this procedure is to move series in a chart
'so that the data in the chart moves with the data
'as FocusMonth changes.
'=======================================================
'=======================================================
'Get the column of the oldest month - subtract
'3 because the oldest month is 3 months before
'the focus month
OldestMonthCol = WorksheetFunction.Match(FocusMonth, Range("Date"
'Since we always display 6 in the window, the newest
'month 5 more than Oldest
NewestMonthCol = OldestMonthCol + 5
ChartName = Worksheets("Quad Chart"
ActiveSheet.ChartObjects(ChartName).Activate
Dim DataRange As Range
Dim WindowRange As Range
Dim DataSheet As Worksheet
Set DataSheet = Sheets("Data"
With DataSheet
'Create a "window" of 6 dates
Set WindowRange = .Range(.Cells(1, OldestMonthCol).Address, .Cells(1, NewestMonthCol).Address)
'Loop through all the series and change them
For i = 1 To ActiveChart.SeriesCollection.Count
Select Case i
Case 1
theRow = .Range("PT1"
theName = "PT1"
Case 2
theRow = .Range("PT2"
theName = "PT2"
Case 3
theRow = .Range("BAC"
theName = "BAC"
End Select
'set the range for the window of dates in view
Set DataRange = .Range(.Cells(theRow, OldestMonthCol).Address, .Cells(theRow, NewestMonthCol).Address)
ActiveChart.SeriesCollection(theName).XValues = WindowRange
ActiveChart.SeriesCollection(theName).Values = DataRange
Next i
End With
end function