I am having trouble producing charts in VBA. I am having trouble with the portion in the With statement.
I was receiving an error "Unable to get the chartobjects property of the worksheet class" on the line:
The properties I would like to add to the charts are: line chart type, x and y axis labeled, include a chart title, and most importantly because I would like to produce many of the charts I would like to have them added to the sheet one below the other so they are easily visible. Also, I would like to shrink the chart size to a lesser width and height.
The code I have currently is below:
I was receiving an error "Unable to get the chartobjects property of the worksheet class" on the line:
Code:
With Worksheets("LowDistCharts").ChartObjects(aa)
The properties I would like to add to the charts are: line chart type, x and y axis labeled, include a chart title, and most importantly because I would like to produce many of the charts I would like to have them added to the sheet one below the other so they are easily visible. Also, I would like to shrink the chart size to a lesser width and height.
The code I have currently is below:
Code:
Dim aa As IntegerDim StartDate As Range
Dim EndDate As Range
Dim RngStart As String
Dim RngEnd As String
For aa = 5 To 24
ActiveWorkbook.Sheets("AllDistanceMeasures").Activate
Set StartDate = Cells(aa, 9)
Set EndDate = Cells(aa, 10)
ActiveWorkbook.Sheets("ActiveSheet").Activate
RngStart = Cells.Find(What:=StartDate, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Address(1, 1)
RngEnd = Cells.Find(What:=EndDate, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Offset(0, 1).Address(1, 1)
With Worksheets("LowDistCharts").ChartObjects(aa)
.HasTitle = True
.ChartTitle.Text = aa & StartDate & "to" & EndDate
'.Placement =
.RoundedCorners = True
.SetSourceData Source:=Range("LowDistCharts!RngStart:RngEnd")
.ChartType = xlLine
End With