A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
The following code is correct. It does create a minor problem. If the chart exists, I want to delete it. As far as the chart postion and sizing goes, it is good. I found this code on a posting from Bill Manville dated September 15, 2010. He should get credit for the solution. Thanks to all. Bill Roberts
Public FirstCell As Object
Public rngsource As Range
Public rng1 As Range
Public rng2 As Range
Public rng3 As Range
Sub Chart()
Sheets("MASTER").Select
Cells(maxdays - 60, "B").Select
Set FirstCell = ActiveCell
Set rng1 = Range(FirstCell.Offset(0, 0), FirstCell.Offset(62, 0))
Set rng2 = Range(FirstCell.Offset(0, 7), FirstCell.Offset(62, 7))
Set rng3 = Range(FirstCell.Offset(0, 8), FirstCell.Offset(62, 8))
ActiveSheet.Shapes.AddChart.Select
Set rngsource = Union(rng1, rng2, rng3)
ActiveChart.SetSourceData Source:=rngsource, PlotBy:=xlColumns
ActiveChart.SeriesCollection(2).Select
ActiveChart.SeriesCollection(2).AxisGroup = 2
With ActiveChart
.HasLegend = False
.Axes(xlCategory).HasMajorGridlines = True
.Axes(xlValue, xlPrimary).HasMajorGridlines = False
.Axes(xlValue, xlSecondary).HasMajorGridlines = True
.SeriesCollection(1).Select
With Selection
.MarkerStyle = 1
.MarkerSize = 4
End With
.SeriesCollection(2).Select
With Selection
.MarkerSize = 4
.MarkerStyle = 3
End With
.ChartArea.Select
End With
With ActiveChart.Parent.ShapeRange 'This is the critical line and the code Bill Manville suggested
.IncrementLeft 100
.IncrementTop 250
.ScaleWidth 1.3, msoFalse, msoScaleFromTopLeft
.ScaleHeight 1.4, msoFalse, msoScaleFromTopLeft
ActiveWindow.SmallScroll ToRight:=5
End With
End Sub
Bill Roberts