Ed,
First of all thank you for your help. I tried what you mentioned and I'm
sorry to say that I couldn't really get any valuable information out of it.
When I run the Debug.Print statements I get the correct values for the rows
and columns of my ranges and the union, even when the SetSourceData method
fails.
Any other ideas? I've attached the whole sub below... Thanks again, you're
the only person to offer help and Im very grateful.
Private Sub Display_Charts(ByVal MonthVar As Variant, ByVal WeekVar As
Variant, ByVal AsOfDate As Date)
Dim CWeek As Range, CBCWP As Range, CBCWS As Range, CACWP As Range
Dim CCV As Range, CCPI As Range, CSV As Range, CSPI As Range
Dim CCPIUCL As Range, CCPIAvg As Range, CCPILCL As Range, CCPIUSL As Range,
CCPITarget As Range, CCPILSL As Range
Dim CSPIUCL As Range, CSPIAvg As Range, CSPILCL As Range, CSPIUSL As Range,
CSPITarget As Range, CSPILSL As Range
Dim CCVUCL As Range, CCVAvg As Range, CCVLCL As Range, CCVUSL As Range,
CCVTarget As Range, CCVLSL As Range
Dim CSVUCL As Range, CSVAvg As Range, CSVLCL As Range, CSVUSL As Range,
CSVTarget As Range, CSVLSL As Range
Dim co2SD As Range, co3SD As Range, co4SD As Range, co5SD As Range
Dim co2 As ChartObject, co3 As ChartObject, co4 As ChartObject, co5 As
ChartObject
xlApp.Calculation = xlCalculationAutomatic 'Set Calculation back to
automatic for the Excel File
With xlBook.Worksheets(3)
'Set up the Chart Ranges based on the dates selected to run the report
Set CWeek = ActiveSheet.Range(Cells((20 + MonthVar), 1), Cells((21 +
MonthVar + WeekVar), 1))
Set CBCWP = ActiveSheet.Range(Cells((20 + MonthVar), 3), Cells((21 +
MonthVar + WeekVar), 3))
Set CBCWS = ActiveSheet.Range(Cells((20 + MonthVar), 2), Cells((21 +
MonthVar + WeekVar), 2))
Set CACWP = ActiveSheet.Range(Cells((20 + MonthVar), 4), Cells((21 +
MonthVar + WeekVar), 4))
Set CCV = ActiveSheet.Range(Cells((20 + MonthVar), 5), Cells((21 +
MonthVar + WeekVar), 5))
Set CCPI = ActiveSheet.Range(Cells((20 + MonthVar), 6), Cells((21 +
MonthVar + WeekVar), 6))
Set CSV = ActiveSheet.Range(Cells((20 + MonthVar), 7), Cells((21 +
MonthVar + WeekVar), 7))
Set CSPI = ActiveSheet.Range(Cells((20 + MonthVar), 8), Cells((21 +
MonthVar + WeekVar), 8))
Set CCPIUCL = ActiveSheet.Range(Cells((20 + MonthVar), 12),
Cells((21 + MonthVar + WeekVar), 12))
Set CCPIAvg = ActiveSheet.Range(Cells((20 + MonthVar), 13),
Cells((21 + MonthVar + WeekVar), 13))
Set CCPILCL = ActiveSheet.Range(Cells((20 + MonthVar), 14),
Cells((21 + MonthVar + WeekVar), 14))
Set CCPIUSL = ActiveSheet.Range(Cells((20 + MonthVar), 15),
Cells((21 + MonthVar + WeekVar), 15))
Set CCPITarget = ActiveSheet.Range(Cells((20 + MonthVar), 16),
Cells((21 + MonthVar + WeekVar), 16))
Set CCPILSL = ActiveSheet.Range(Cells((20 + MonthVar), 17),
Cells((21 + MonthVar + WeekVar), 17))
Set CSPIUCL = ActiveSheet.Range(Cells((20 + MonthVar), 18),
Cells((21 + MonthVar + WeekVar), 18))
Set CSPIAvg = ActiveSheet.Range(Cells((20 + MonthVar), 19),
Cells((21 + MonthVar + WeekVar), 19))
Set CSPILCL = ActiveSheet.Range(Cells((20 + MonthVar), 20),
Cells((21 + MonthVar + WeekVar), 20))
Set CSPIUSL = ActiveSheet.Range(Cells((20 + MonthVar), 21),
Cells((21 + MonthVar + WeekVar), 21))
Set CSPITarget = ActiveSheet.Range(Cells((20 + MonthVar), 22),
Cells((21 + MonthVar + WeekVar), 22))
Set CSPILSL = ActiveSheet.Range(Cells((20 + MonthVar), 23),
Cells((21 + MonthVar + WeekVar), 23))
Set CCVUCL = ActiveSheet.Range(Cells((20 + MonthVar), 24), Cells((21
+ MonthVar + WeekVar), 24))
Set CCVAvg = ActiveSheet.Range(Cells((20 + MonthVar), 25), Cells((21
+ MonthVar + WeekVar), 25))
Set CCVLCL = ActiveSheet.Range(Cells((20 + MonthVar), 26), Cells((21
+ MonthVar + WeekVar), 26))
Set CCVUSL = ActiveSheet.Range(Cells((20 + MonthVar), 27), Cells((21
+ MonthVar + WeekVar), 27))
Set CCVTarget = ActiveSheet.Range(Cells((20 + MonthVar), 28),
Cells((21 + MonthVar + WeekVar), 28))
Set CCVLSL = ActiveSheet.Range(Cells((20 + MonthVar), 29), Cells((21
+ MonthVar + WeekVar), 29))
Set CSVUCL = ActiveSheet.Range(Cells((20 + MonthVar), 30), Cells((21
+ MonthVar + WeekVar), 30))
Set CSVAvg = ActiveSheet.Range(Cells((20 + MonthVar), 31), Cells((21
+ MonthVar + WeekVar), 31))
Set CSVLCL = ActiveSheet.Range(Cells((20 + MonthVar), 32), Cells((21
+ MonthVar + WeekVar), 32))
Set CSVUSL = ActiveSheet.Range(Cells((20 + MonthVar), 33), Cells((21
+ MonthVar + WeekVar), 33))
Set CSVTarget = ActiveSheet.Range(Cells((20 + MonthVar), 34),
Cells((21 + MonthVar + WeekVar), 34))
Set CSVLSL = ActiveSheet.Range(Cells((20 + MonthVar), 35), Cells((21
+ MonthVar + WeekVar), 35))
End With
'Set Unions for each chart range for source data
Debug.Print CWeek.Rows.Count
Debug.Print CWeek.Columns.Count
Debug.Print CCPI.Rows.Count
Debug.Print CCPI.Columns.Count
Debug.Print CCPIUCL.Rows.Count
Debug.Print CCPIUCL.Columns.Count
Debug.Print CCPIAvg.Rows.Count
Debug.Print CCPIAvg.Columns.Count
Debug.Print CCPILCL.Rows.Count
Debug.Print CCPILCL.Columns.Count
Debug.Print CCPIUSL.Rows.Count
Debug.Print CCPIUSL.Columns.Count
Debug.Print CCPITarget.Rows.Count
Debug.Print CCPITarget.Columns.Count
Debug.Print CCPILSL.Rows.Count
Debug.Print CCPILSL.Columns.Count
Set co2SD = Union(CWeek, CCPI, CCPIUCL, CCPIAvg, CCPILCL, CCPIUSL,
CCPITarget, CCPILSL)
Set co3SD = Union(CWeek, CSPI, CSPIUCL, CSPIAvg, CSPILCL, CSPIUSL,
CSPITarget, CSPILSL)
Set co4SD = Union(CWeek, CCV, CCVUCL, CCVAvg, CCVLCL, CCVUSL, CCVTarget,
CCVLSL)
Set co5SD = Union(CWeek, CSV, CSVUCL, CSVAvg, CSVLCL, CSVUSL, CSVTarget,
CSVLSL)
Debug.Print co2SD.Rows.Count
Debug.Print co2SD.Columns.Count
'Move to Sheet #4
xlBook.Worksheets(4).Select
xlBook.Worksheets(4).Name = "Report Graphs"
Set xlR = xlBook.Worksheets(4).Range("A1")
With xlR
.Formula = "Cost and Schedule Weekly Charts for " & ActiveProject.Name
.Font.Bold = True
.Font.Size = 14
.ColumnWidth = 21
End With
With xlR.Range("A2")
.Formula = "As of: "
.Font.Bold = True
.Font.Size = 12
End With
With xlR.Range("B2")
.Formula = AsOfDate
.NumberFormat = "mm/dd/yyyy"
.Font.Bold = True
.Font.Size = 12
.ColumnWidth = 12
End With
' Create 2nd Chart showing the Cost Performance Index
Set co2 = xlBook.Worksheets(4).ChartObjects.Add(5, 100, 700, 380)
co2.Chart.ChartType = xlLineMarkers
co2.Chart.SetSourceData Source:=co2SD, _
PlotBy:=xlColumns
co2.Chart.Location Where:=xlLocationAsObject, Name:="Report Graphs"
With co2.Chart
.HasTitle = True
.ChartTitle.Characters.Text = "CPI Graph"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Week"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Index"
End With
With co2.Chart
.HasAxis(xlCategory, xlPrimary) = True
.HasAxis(xlValue, xlPrimary) = True
End With
co2.Chart.Axes(xlCategory, xlPrimary).CategoryType = xlCategoryScale
co2.Chart.Axes(xlValue).HasMajorGridlines = False
co2.Chart.HasLegend = True
co2.Chart.Legend.Position = xlLegendPositionBottom
' co2.Chart.HasDataTable = True
' co2.Chart.DataTable.ShowLegendKey = True
co2.Chart.SeriesCollection(1).Border.Weight = xlMedium
co2.Chart.SeriesCollection(2).Select
With Selection.Border
.ColorIndex = 3
.Weight = xlThin
.LineStyle = xlDot
End With
Selection.MarkerStyle = xlNone
co2.Chart.SeriesCollection(3).Select
With Selection.Border
.Color = RGB(120, 120, 120)
.Weight = xlThin
End With
Selection.MarkerStyle = xlNone
co2.Chart.SeriesCollection(4).Select
With Selection.Border
.ColorIndex = 3
.Weight = xlThin
.LineStyle = xlDot
End With
Selection.MarkerStyle = xlNone
co2.Chart.SeriesCollection(5).Select
With Selection.Border
.ColorIndex = 5
.Weight = xlMedium
.LineStyle = xlDot
End With
Selection.MarkerStyle = xlNone
co2.Chart.SeriesCollection(6).Select
With Selection.Border
.ColorIndex = 1
.Weight = xlMedium
End With
Selection.MarkerStyle = xlNone
co2.Chart.SeriesCollection(7).Select
With Selection.Border
.ColorIndex = 5
.Weight = xlMedium
.LineStyle = xlDot
End With
Selection.MarkerStyle = xlNone
' Create 3rd Chart showing the Schedule Efficiency Index
Set co3 = xlBook.Worksheets(4).ChartObjects.Add(5, 495, 700, 380)
co3.Chart.ChartType = xlLineMarkers
co3.Chart.SetSourceData Source:=co3SD, _
PlotBy:=xlColumns
co3.Chart.Location Where:=xlLocationAsObject, Name:="Report Graphs"
With co3.Chart
.HasTitle = True
.ChartTitle.Characters.Text = "SPI Graph"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Week"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Index"
End With
With co3.Chart
.HasAxis(xlCategory, xlPrimary) = True
.HasAxis(xlValue, xlPrimary) = True
End With
co3.Chart.Axes(xlCategory, xlPrimary).CategoryType = xlCategoryScale
co3.Chart.Axes(xlValue).HasMajorGridlines = False
co3.Chart.HasLegend = True
co3.Chart.Legend.Position = xlLegendPositionBottom
' co3.Chart.HasDataTable = True
' co3.Chart.DataTable.ShowLegendKey = True
co3.Chart.SeriesCollection(1).Border.Weight = xlMedium
co3.Chart.SeriesCollection(2).Select
With Selection.Border
.ColorIndex = 3
.Weight = xlThin
.LineStyle = xlDot
End With
Selection.MarkerStyle = xlNone
co3.Chart.SeriesCollection(3).Select
With Selection.Border
.Color = RGB(120, 120, 120)
.Weight = xlThin
End With
Selection.MarkerStyle = xlNone
co3.Chart.SeriesCollection(4).Select
With Selection.Border
.ColorIndex = 3
.Weight = xlThin
.LineStyle = xlDot
End With
Selection.MarkerStyle = xlNone
co3.Chart.SeriesCollection(5).Select
With Selection.Border
.ColorIndex = 5
.Weight = xlMedium
.LineStyle = xlDot
End With
Selection.MarkerStyle = xlNone
co3.Chart.SeriesCollection(6).Select
With Selection.Border
.ColorIndex = 1
.Weight = xlMedium
End With
Selection.MarkerStyle = xlNone
co3.Chart.SeriesCollection(7).Select
With Selection.Border
.ColorIndex = 5
.Weight = xlMedium
.LineStyle = xlDot
End With
Selection.MarkerStyle = xlNone
' Create 4th Chart showing the Cost Variance
Set co4 = xlBook.Worksheets(4).ChartObjects.Add(5, 890, 700, 380)
co4.Chart.ChartType = xlLineMarkers
co4.Chart.SetSourceData Source:=co4SD, PlotBy:=xlColumns
co4.Chart.Location Where:=xlLocationAsObject, Name:="Report Graphs"
With co4.Chart
.HasTitle = True
.ChartTitle.Characters.Text = "CV Graph"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Week"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Dollars"
End With
With co4.Chart
.HasAxis(xlCategory, xlPrimary) = True
.HasAxis(xlValue, xlPrimary) = True
End With
co4.Chart.Axes(xlCategory, xlPrimary).CategoryType = xlCategoryScale
co4.Chart.Axes(xlValue).HasMajorGridlines = False
co4.Chart.HasLegend = True
co4.Chart.Legend.Position = xlLegendPositionBottom
' co4.Chart.HasDataTable = True
' co4.Chart.DataTable.ShowLegendKey = True
co4.Chart.SeriesCollection(1).Border.Weight = xlMedium
co4.Chart.SeriesCollection(2).Select
With Selection.Border
.ColorIndex = 3
.Weight = xlThin
.LineStyle = xlDot
End With
Selection.MarkerStyle = xlNone
co4.Chart.SeriesCollection(3).Select
With Selection.Border
.Color = RGB(120, 120, 120)
.Weight = xlThin
End With
Selection.MarkerStyle = xlNone
co4.Chart.SeriesCollection(4).Select
With Selection.Border
.ColorIndex = 3
.Weight = xlThin
.LineStyle = xlDot
End With
Selection.MarkerStyle = xlNone
co4.Chart.SeriesCollection(5).Select
With Selection.Border
.ColorIndex = 5
.Weight = xlMedium
.LineStyle = xlDot
End With
Selection.MarkerStyle = xlNone
co4.Chart.SeriesCollection(6).Select
With Selection.Border
.ColorIndex = 1
.Weight = xlMedium
End With
Selection.MarkerStyle = xlNone
co4.Chart.SeriesCollection(7).Select
With Selection.Border
.ColorIndex = 5
.Weight = xlMedium
.LineStyle = xlDot
End With
Selection.MarkerStyle = xlNone
' Create 5th Chart showing the Schedule Variance
Set co5 = xlBook.Worksheets(4).ChartObjects.Add(5, 1285, 700, 380)
co5.Chart.ChartType = xlLineMarkers
co5.Chart.SetSourceData Source:=co5SD, PlotBy:=xlColumns
co5.Chart.Location Where:=xlLocationAsObject, Name:="Report Graphs"
With co5.Chart
.HasTitle = True
.ChartTitle.Characters.Text = "SV Graph"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Week"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Dollars"
End With
With co5.Chart
.HasAxis(xlCategory, xlPrimary) = True
.HasAxis(xlValue, xlPrimary) = True
End With
co5.Chart.Axes(xlCategory, xlPrimary).CategoryType = xlCategoryScale
co5.Chart.Axes(xlValue).HasMajorGridlines = False
co5.Chart.HasLegend = True
co5.Chart.Legend.Position = xlLegendPositionBottom
' co5.Chart.HasDataTable = True
' co5.Chart.DataTable.ShowLegendKey = True
co5.Chart.SeriesCollection(1).Border.Weight = xlMedium
co5.Chart.SeriesCollection(2).Select
With Selection.Border
.ColorIndex = 3
.Weight = xlThin
.LineStyle = xlDot
End With
Selection.MarkerStyle = xlNone
co5.Chart.SeriesCollection(3).Select
With Selection.Border
.Color = RGB(120, 120, 120)
.Weight = xlThin
End With
Selection.MarkerStyle = xlNone
co5.Chart.SeriesCollection(4).Select
With Selection.Border
.ColorIndex = 3
.Weight = xlThin
.LineStyle = xlDot
End With
Selection.MarkerStyle = xlNone
co5.Chart.SeriesCollection(5).Select
With Selection.Border
.ColorIndex = 5
.Weight = xlMedium
.LineStyle = xlDot
End With
Selection.MarkerStyle = xlNone
co5.Chart.SeriesCollection(6).Select
With Selection.Border
.ColorIndex = 1
.Weight = xlMedium
End With
Selection.MarkerStyle = xlNone
co5.Chart.SeriesCollection(7).Select
With Selection.Border
.ColorIndex = 5
.Weight = xlMedium
.LineStyle = xlDot
End With
Selection.MarkerStyle = xlNone
' Set Page Setup for printing the Graphs
With xlBook.Worksheets(4).PageSetup
.PrintTitleRows = "$1:$6"
.PrintTitleColumns = ""
.LeftFooter = "&A"
.CenterFooter = "Page &P of &N"
.RightFooter = "&D"
End With
' xlBook.Worksheets(4).PageSetup.PrintArea = "$A$4:$M$161"
With xlBook.Worksheets(4).PageSetup
.LeftMargin = xlApp.InchesToPoints(0.5)
.RightMargin = xlApp.InchesToPoints(0.5)
.CenterHorizontally = True
.CenterVertically = True
.Orientation = xlLandscape
.PaperSize = xlPaperLetter
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = False
End With
'Reset Variables
Set co2 = Nothing
Set co3 = Nothing
Set co4 = Nothing
Set co5 = Nothing
Set co2SD = Nothing
Set co3SD = Nothing
Set co4SD = Nothing
Set co5SD = Nothing
Set CWeek = Nothing
Set CBCWP = Nothing
Set CBCWS = Nothing
Set CACWP = Nothing
Set CCV = Nothing
Set CCPI = Nothing
Set CSV = Nothing
Set CSPI = Nothing
Set CCPIUCL = Nothing
Set CCPIAvg = Nothing
Set CCPILCL = Nothing
Set CCPIUSL = Nothing
Set CCPITarget = Nothing
Set CCPILSL = Nothing
Set CSPIUCL = Nothing
Set CSPIAvg = Nothing
Set CSPILCL = Nothing
Set CSPIUSL = Nothing
Set CSPITarget = Nothing
Set CSPILSL = Nothing
Set CCVUCL = Nothing
Set CCVAvg = Nothing
Set CCVLCL = Nothing
Set CCVUSL = Nothing
Set CCVTarget = Nothing
Set CCVLSL = Nothing
Set CSVUCL = Nothing
Set CSVAvg = Nothing
Set CSVLCL = Nothing
Set CSVUSL = Nothing
Set CSVTarget = Nothing
Set CSVLSL = Nothing
Set MonthVar = Nothing
Set WeekVar = Nothing
End Sub