Team,
I have code which is creating chart about active sheet.
I need to use this code to create a few charts in seperate sheets,
for example:
- sheet1 - had data to 3 charts
- sheet2 - had data to 2 charts
- sheet3 - had data to 5 charts.
I don't want to duplicate my module for each chart (this makes no sense). I think I use some proceuder to call my function but add some new source data for each charts.
Please help me how to do it.
my code:
regards,
PvK
I have code which is creating chart about active sheet.
I need to use this code to create a few charts in seperate sheets,
for example:
- sheet1 - had data to 3 charts
- sheet2 - had data to 2 charts
- sheet3 - had data to 5 charts.
I don't want to duplicate my module for each chart (this makes no sense). I think I use some proceuder to call my function but add some new source data for each charts.
Please help me how to do it.
my code:
Code:
Sub CreateAChart()
'create an embedded chart
Dim co As ChartObject
'position chart using column width and row height units
Set co = ActiveSheet.ChartObjects.Add(100, 100, 400, 300)
'set chart type
co.Chart.ChartType = xlLine 'xlPie
'name it
co.Name = "ChartExample"
'Debug.Print co.Name
'Debug.Print co.Chart.Name
'add data series
co.Chart.SeriesCollection.Add _
Source:=ActiveSheet.Range("A1:C6"), _
Rowcol:=xlColumns, SeriesLabels:=True, _
Categorylabels:=True
'add axes (default settings - here is for illustration)
With co.Chart
.HasAxis(xlCategory, xlPrimary) = True
.HasAxis(xlCategory, xlSecondary) = False
.HasAxis(xlValue, xlPrimary) = True
.HasAxis(xlValue, xlSecondary) = False
End With
'axis title formatting
With co.Chart.Axes(xlCategory)
.HasTitle = True
.AxisTitle.Caption = "Types"
.AxisTitle.Border.Weight = xlMedium
End With
With co.Chart.Axes(xlValue)
.HasTitle = True
With .AxisTitle
.Caption = "Quantity for 1999"
.Font.Size = 8
.Orientation = xlHorizontal
.Characters(14, 4).Font.Italic = True
.Border.Weight = xlMedium
End With
End With
'change the category name (Types) to lower case (1 kolumna)
co.Chart.Axes(xlCategory).CategoryNames = _
Array("a", "b", "c", "d", "e")
'set the crossing point on the (primary) value axis at 50
co.Chart.Axes(xlValue).CrossesAt = 50
'horizontal but no vertical gridlines (siatka na wykresie)
co.Chart.Axes(xlValue).HasMajorGridlines = True 'pozioma
co.Chart.Axes(xlCategory).HasMajorGridlines = False 'pionowa
'outside Tickmarks on category axis
co.Chart.Axes(xlCategory).MajorTickMark = xlTickMarkCross
'move tick labels to below chart area
co.Chart.Axes(xlCategory).TickLabelPosition = _
xlTickLabelPositionNextToAxis
'set chart area fill to solid white
co.Chart.ChartArea.Interior.Color = RGB(255, 255, 255)
'set plot area fill to gray
co.Chart.PlotArea.Interior.ColorIndex = 15
With co.Chart.SeriesCollection(1)
.MarkerSize = 10
.MarkerStyle = xlMarkerStyleDiamond
With .Points(2)
.MarkerSize = 20
.MarkerStyle = xlMarkerStyleCircle
End With
End With
End Sub
regards,
PvK