PDA

View Full Version : Solved: Excel Charts - Naming



khalid79m
05-20-2009, 02:00 AM
How do I write a macro to round corners on my graphs.


Private Sub Cons()
Dim LastRow As Long
With Sheets("CONS")
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
Charts.Add
ActiveChart.ChartType = xlColumnClustered
ActiveChart.SetSourceData Source:=Sheets("CONS").Range("F1:J" & LastRow), PlotBy:= _
xlColumns

ActiveChart.SeriesCollection(1).XValues = Sheets("CONS").Range("A2:A" & LastRow)
ActiveChart.SeriesCollection(2).XValues = Sheets("CONS").Range("A2:A" & LastRow)
ActiveChart.SeriesCollection(3).XValues = Sheets("CONS").Range("A2:A" & LastRow)
ActiveChart.SeriesCollection(4).XValues = Sheets("CONS").Range("A2:A" & LastRow)
ActiveChart.SeriesCollection(5).XValues = Sheets("CONS").Range("A2:A" & LastRow)

ActiveChart.Name = "AVC"
ActiveChart.Location Where:=xlLocationAsObject, Name:="Data3"

With Charts("AVC")
.DrawingObjects.RoundedCorners = True
End With


End

Also how do I name the chart something other than Chart1 , Chart2 etc as everytime I write a macro , and run it the Chart number keeps rising , is there a way to name the chart for vba ? if that makes sense

Bob Phillips
05-20-2009, 03:21 AM
I don't think you can round the corners.

Doesn't you code already ename the chart?

Andy Pope
05-20-2009, 04:04 AM
Private Sub Cons()
Dim LastRow As Long
With Sheets("CONS")
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
Charts.Add
ActiveChart.ChartType = xlColumnClustered
ActiveChart.SetSourceData Source:=Sheets("CONS").Range("F1:J" & LastRow), PlotBy:= _
xlColumns

ActiveChart.SeriesCollection(1).XValues = Sheets("CONS").Range("A2:A" & LastRow)
ActiveChart.SeriesCollection(2).XValues = Sheets("CONS").Range("A2:A" & LastRow)
ActiveChart.SeriesCollection(3).XValues = Sheets("CONS").Range("A2:A" & LastRow)
ActiveChart.SeriesCollection(4).XValues = Sheets("CONS").Range("A2:A" & LastRow)
ActiveChart.SeriesCollection(5).XValues = Sheets("CONS").Range("A2:A" & LastRow)

ActiveChart.Name = "AVC"
ActiveChart.Location Where:=xlLocationAsObject, Name:="Data3"

With Sheets("Data3")
With .ChartObjects(.ChartObjects.Count)
.Name = "AVC"
.RoundedCorners = True
End With
End With


End Sub

Bob Phillips
05-20-2009, 04:32 AM
Okay, so I was wrong, I didn't know you could do that. But I have to ask, why? It is totally pointless IMO.

khalid79m
05-20-2009, 07:04 AM
ActiveChart.Parent.RoundedCorners = True


How about the above,