PDA

View Full Version : Change marker size for all series in a plot (VBA)



Roboquist
08-16-2017, 09:56 PM
I've recently been working on a piece of code that will change the appearence of all Charts in a sheet to look the same.
So far I've been able to fix the size aswell as some other attributes but I can't get my head around changing the appearence for all series within each chart.

My code so far looks like this:

Sub ResizeCharts()
'Standard
Dim cht As ChartObject
For Each cht In ActiveSheet.ChartObjects

'Chart Size
cht.Height = 750
cht.Width = 452

'Plot Area Size
cht.Chart.PlotArea.Width = 380
cht.Chart.PlotArea.Height = 680
cht.Chart.PlotArea.Left = 40
cht.Chart.PlotArea.Top = 40

'Position Titel X-axis
cht.Chart.Axes(xlCategory).AxisTitle.Left = cht.Chart.Axes(xlCategory).Left + (cht.Chart.Axes(xlCategory).Width - cht.Chart.Axes(xlCategory).AxisTitle.Width) / 2
cht.Chart.Axes(xlCategory).AxisTitle.Top = (cht.Chart.PlotArea.Top - cht.Chart.Axes(xlCategory).Height) / 2

''Position Titel Y-axis
cht.Chart.Axes(xlValue).AxisTitle.Top = cht.Chart.Axes(xlValue).Top + (cht.Chart.Axes(xlValue).Height - cht.Chart.Axes(xlValue).AxisTitle.Height) / 2
cht.Chart.Axes(xlValue).AxisTitle.Left = (cht.Chart.PlotArea.Left - cht.Chart.Axes(xlValue).Width) / 2

'Legend Settings
cht.Chart.Legend.Font.Size = 10


Next
End Sub


For example i want to change the marker size to 7 in all series of all charts. Does anyone have a solution for this?

Greatly thankful

Aflatoon
08-17-2017, 12:20 AM
You could do something like this:


Sub ResizeCharts()'Standard
Dim cht As ChartObject
Dim ser As Series
For Each cht In ActiveSheet.ChartObjects
With cht
'Chart Size
.Height = 750
.Width = 452


'Plot Area Size
With .Chart.PlotArea
.Width = 380
.Height = 680
.Left = 40
.Top = 40
End With


'Position Titel X-axis
With .Chart.Axes(xlCategory)
If .HasTitle Then
.AxisTitle.Left = .Left + (.Width - .AxisTitle.Width) / 2
.AxisTitle.Top = (cht.Chart.PlotArea.Top - .Height) / 2
End If
End With


''Position Titel Y-axis
With .Chart.Axes(xlValue)
If .HasTitle Then
.AxisTitle.Top = .Top + (.Height - .AxisTitle.Height) / 2
.AxisTitle.Left = (cht.Chart.PlotArea.Left - .Width) / 2
End If
End With
With .Chart
'Legend Settings
.Legend.Font.Size = 10


' set marker sizes - error handler is to skip if no markers
On Error Resume Next
For Each ser In .SeriesCollection
ser.MarkerSize = 10
Next
On Error GoTo 0
End With
End With


Next
End Sub

Roboquist
08-17-2017, 01:03 AM
Wonderful that's exactly what I need, thank you!