Put in X axis counter timer from integer in Excel Chart - excel

In my Excel chart, the Xaxis shows sequential integers representing seconds in multiples of 10:
10 20 30 40 50 60 70 80 90 100 and so on
How to show in this Xaxis minutes and seconds like this:
00:00 00:10 00:20 00:30 00:40 00:50 01:00 01:10 01:20 01:30 and so on
I use the VBA below to generate the chart.
Sub NewChart()
'Create a chart
Sheets(1).Select 'Select the active Sheet
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlXYScatter
LastLine = Sheets(2).Range("A" & Rows.Count).End(xlUp).Row
Dim MaxScale As Integer
Dim MTotal As Integer
Dim Aprox As Integer
Dim vName As String
vName = Sheets(2).Range("B3")
Dim Qx As Integer
Qx = LastLine - 1
Dim Rangg As Integer
Rangg = (LastLine * 10) - 60
MTotal = Rangg
MaxScale = Rangg + 20
With ActiveChart
.ChartType = xlXYScatter
'Set data source range.
.SetSourceData Source:=Sheets(2).Range("A5:A" & Qx & ",B5:B" & Qx & ",E5:E" & Qx & ",H5:H" & Qx & ", K5:K" & Qx & ", N5:N" & Qx & ", Q5:Q" & Qx) ', 'PlotBy:=xlRows
.HasTitle = True
.ChartTitle.Text = vName '"2-7μm"
'The Parent property is used to set properties of the Chart.
With .Parent
.Top = 2
.Left = 2
.Width = 540
.Height = 252
.Name = "2micron"
End With
ActiveChart.Legend.Select
With Selection.Format.TextFrame2.TextRange.Font
.NameComplexScript = "Tahoma"
.NameFarEast = "Tahoma"
.Name = "Tahoma"
End With
.Axes(xlCategory).MajorTickMark = xlInside
.Axes(xlCategory).MinorTickMark = xlInside
.Axes(xlCategory, xlPrimary).Select
.Axes(xlCategory, xlPrimary).TickLabels.Font.Size = 5
.Axes(xlCategory, xlPrimary).TickLabels.Font.Name = "Tahoma"
.Axes(xlCategory, xlPrimary).TickLabels.Font.Bold = msoTrue
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Time (seconds)"
.Axes(xlCategory, xlPrimary).AxisTitle.Font.Size = 11
.Axes(xlCategory, xlPrimary).AxisTitle.Font.Bold = msoTrue
.Axes(xlCategory, xlPrimary).AxisTitle.Font.Name = "Tahoma"
.Axes(xlCategory, xlPrimary).MinorUnitIsAuto = False
.Axes(xlCategory, xlPrimary).MajorUnit = 300
.Axes(xlCategory, xlPrimary).MinorUnit = 60
.Axes(xlCategory, xlPrimary).MaximumScale = MaxScale
.Axes(xlCategory, xlPrimary).MinimumScale = 0
.Axes(xlCategory, xlPrimary).HasMajorGridlines = True
.Axes(xlCategory, xlPrimary).HasMinorGridlines = True
.Axes(xlCategory).Format.Line.ForeColor.RGB = RGB(0, 0, 0)
.Axes(xlValue).MajorTickMark = xlInside
.Axes(xlValue).MinorTickMark = xlInside
.Axes(xlValue, xlPrimary).Select
.Axes(xlValue, xlPrimary).HasMajorGridlines = True
.Axes(xlValue, xlPrimary).HasMinorGridlines = True
.Axes(xlValue, xlPrimary).TickLabels.Font.Size = 11
.Axes(xlValue, xlPrimary).TickLabels.Font.Name = "Tahoma"
.Axes(xlValue, xlPrimary).TickLabels.Font.Bold = msoTrue
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Y axis Legend"
.Axes(xlValue, xlPrimary).AxisTitle.Font.Size = 11
.Axes(xlValue, xlPrimary).AxisTitle.Font.Name = "Tahoma"
.Axes(xlValue, xlPrimary).AxisTitle.Font.Bold = msoTrue
.Axes(xlValue).Format.Line.ForeColor.RGB = RGB(0, 0, 0)
.Legend.IncludeInLayout = False
.Legend.Select
Selection.Position = xlTop
Selection.Font.Size = 11
Selection.Font.Name = "Tahoma"
Selection.Font.Bold = msoTrue
ActiveSheet.Shapes("2micron").ScaleWidth 1, msoFalse, _
msoScaleFromTopLeft
ActiveChart.SetElement (msoElementChartTitleAboveChart)
ActiveChart.ChartTitle.Select
Selection.Left = 2
Selection.Top = 2
Selection.Format.TextFrame2.TextRange.Font.Size = 13.2
Selection.Format.TextFrame2.TextRange.Font.Name = "Tahoma"
Selection.Format.TextFrame2.TextRange.Font.Bold = msoTrue
ActiveChart.Legend.Select
Selection.Left = 180
Selection.Top = 2
With Selection.Format.Line
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorAccent1
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = 0
End With
ActiveChart.PlotArea.Select
Selection.Top = 22
Selection.Left = 20
Selection.Height = 207
Selection.Width = 540
Selection.Border.LineStyle = xlSolid
Selection.Border.Color = vbBlack
Selection.Interior.Color = vbWhite
End With
Call f_l2m1(1, 8, RGB(0, 176, 240))
Call f_l2m1(2, 3, RGB(255, 0, 0))
Call f_l2m1(3, 1, RGB(255, 0, 255))
Call f_l2m1(4, 2, RGB(153, 0, 255))
Call f_l2m1(5, 4, RGB(153, 0, 255))
Call f_l2m1(6, 9, RGB(146, 208, 80))
Range("a22").Select
End Sub
Sub f_l2m1(LineNo, MStyle, vRGB)
With ActiveSheet.ChartObjects("2micron").Chart
ActiveChart.SeriesCollection(LineNo).Select
With Selection
.MarkerStyle = MStyle
.MarkerSize = 7
.MarkerForegroundColor = vRGB
End With
Selection.Format.Fill.Visible = msoFalse
Selection.Format.Line.Visible = msoFalse
Selection.Format.Line.ForeColor.RGB = vRGB
End With
End Sub

Convert your data from whole number seconds to actual times:
Divide by 86400 (60sec/min*60min/hr*24hr/day)
Use number format MM:SS
Make sure chart is an XY chart. X axis should pick up MM:SS format from data, but if not you can format it by formatting the axis.

Related

Generating second axis in a chart vba

I wanted to create a second axis in my chart.
There is no error when i run ".SeriesCollection(1).AxisGroup=2" but it does not create the second axis.
I want to plot temperature at the LHS of the y-axis and power at RHS of the y-axis.
The x-axis is time.
Outcome: I want to see 2 graphs. A graph generated by Col H and Col F and another will be generated by Col R and Col F.
Sub plotGraph()
Dim LastRowOfH As Long, LastRowOfF As Long, LastRowOfR As Long
Dim ColumnHRngData As Range, ColumnFRngData As Range, ColumnRRngData As Range
Dim xAxes As Axis, yAxes As Axis, y2Axes As Axis
Dim srsNew As Series
LastRowOfH = ActiveSheet.Cells(Rows.Count, 8).End(xlUp).Row
LastRowOfF = ActiveSheet.Cells(Rows.Count, 6).End(xlUp).Row
LastRowOfR = ActiveSheet.Cells(Rows.Count, 18).End(xlUp).Row
Set ColumnHRngData = ActiveSheet.Range("H31:H" & LastRowOfH)
Set ColumnFRngData = ActiveSheet.Range("F31:F" & LastRowOfF)
Set ColumnRRngData = ActiveSheet.Range("R31:R" & LastRowOfR)
Dim cht As Shape
Set cht = ActiveSheet.Shapes.AddChart(Left:=Range("D1:S31").Left, Top:=Range("D1:S31").Top, Width:=Range("D1:S31").Width, Height:=Range("D1:S31").Height)
With cht.Chart
.HasTitle = True
.ChartTitle.Text = "Temperature VS Time"
.ChartType = xlXYScatterLinesNoMarkers
Do Until .SeriesCollection.Count = 0
.SeriesCollection(1).Delete
Loop
Set srsNew = .SeriesCollection.NewSeries
.SeriesCollection(1).Name = "Power/W"
.SeriesCollection(1).Format.Line.ForeColor.RGB = RGB(0, 0, 0) 'change the color of the chart line
.SeriesCollection(1).AxisGroup = 2
With srsNew
.XValues = ColumnFRngData 'xaxis of the graph refers to time in hr
.Values = ColumnHRngData
End With
With srsNew
.XValues = ColumnFRngData
.Values = ColumnRRngData
End With
Set xAxes = .Axes(xlCategory, xlPrimary)
With xAxes
.HasTitle = True
.AxisTitle.Text = "TIME (Hr)"
End With
Set yAxes = .Axes(xlValue, xlPrimary)
With yAxes
.HasTitle = True
.AxisTitle.Text = "Temp (DegCel)"
End With
Set y2Axes = .Axes(xlValue, xlSecondary)
With y2Axes
.HasTitle = True
.AxisTitle.Text = "Power (W)"
End With
End With
You're only plotting one series.
Try this
With cht.Chart
.HasTitle = True
.ChartTitle.Text = "Temperature VS Time"
.ChartType = xlXYScatterLinesNoMarkers
Do While .SeriesCollection.Count > 0
.SeriesCollection(1).Delete 'remove any existing series
Loop
With .SeriesCollection.NewSeries
.Name = "Power/W"
.Format.Line.ForeColor.RGB = RGB(0, 0, 0) 'change the color of the chart line
.AxisGroup = 2
.XValues = ColumnFRngData 'xaxis of the graph refers to time in hr
.Values = ColumnHRngData
End With
With .SeriesCollection.NewSeries
.Name = "Temperature"
.Format.Line.ForeColor.RGB = RGB(255, 0, 0) 'change the color of the chart line
.AxisGroup = 1
.XValues = ColumnFRngData 'xaxis of the graph refers to time in hr
.Values = ColumnRRngData
End With
With .Axes(xlCategory, xlPrimary)
.HasTitle = True
.AxisTitle.Text = "TIME (Hr)"
End With
With .Axes(xlValue, xlPrimary)
.HasTitle = True
.AxisTitle.Text = "Temp (DegCel)"
End With
With .Axes(xlValue, xlSecondary)
.HasTitle = True
.AxisTitle.Text = "Power (W)"
End With
End With

Suggestions for codes format to set the chart coordinates,title and added text in excel macro

Wrote a macro to draw line with markers plot with excel, it works well in a single macro xlsm file. But when I tried to convert it to a excel addin (xlam file) , it got a lot of bugs. All the bugs are related to the format of both X and Y coordinates, position, font type and size of chart title, and position, font type and sizeof added text. Not sure what is the reason, need to know the correct format of them. Any debug suggestions or help, really appreciated. Please see the error message and my full macro codes as the following. Thanks.
The error message is run time error '-21474627161 (800004003)': the object is no longer valid.
After you clicked the debug, the code " .left=358" was highlighted with yellow.
But you checked with excel, the plot was drawn without chart title and the add text (that I want) and the format of coordinate was not that I tried to set. Again all these errors only happen with the xlam file, the macro works well with xlms fie.
Sub strain_plot()
sh_rows = ActiveWorkbook.ActiveSheet.Range("B65535").End(xlUp).Row
For i = 1 To sh_rows
If ActiveSheet.Cells(i, 1).Value < 0.000001 Then
ActiveSheet.Cells(i, 1).Value = 1000000000# * ActiveSheet.Cells(i, 1).Value
End If
Next i
ii = sh_rows
c_name = "chart1"
On Error GoTo err:
ActiveWorkbook.ActiveSheet.ChartObjects(c_name).Delete
err:
Set ch = ActiveWorkbook.ActiveSheet.ChartObjects.Add(330, 120, 480, 270) 'set graph position and size
ch.Name = c_name
With ch.Chart
For iii = 1 To 2
.SeriesCollection.NewSeries
.SeriesCollection(iii).Values = Range(ActiveWorkbook.ActiveSheet.Cells(1, iii + 1), ActiveWorkbook.ActiveSheet.Cells(ii, iii + 1))
.SeriesCollection(iii).XValues = Range(ActiveWorkbook.ActiveSheet.Cells(1, 1), ActiveWorkbook.ActiveSheet.Cells(ii, 1))
.SeriesCollection(iii).ChartType = xlLineMarkers
Next iii
.SeriesCollection(1).Name = "[110]"
.SeriesCollection(1).MarkerStyle = 2
.SeriesCollection(1).MarkerSize = 12
.SeriesCollection(1).MarkerForegroundColor = RGB(255, 0, 0)
.SeriesCollection(1).MarkerBackgroundColor = RGB(255, 0, 0)
.SeriesCollection(1).Format.Fill.ForeColor.RGB = RGB(255, 0, 0)
.SeriesCollection(2).Name = "[001]"
.SeriesCollection(2).MarkerStyle = 2
.SeriesCollection(2).MarkerSize = 12
.SeriesCollection(2).MarkerForegroundColor = RGB(96, 96, 96)
.SeriesCollection(2).MarkerBackgroundColor = RGB(96, 96, 96)
.SeriesCollection(2).Format.Fill.ForeColor.RGB = RGB(96, 96, 96)
With .Legend
.IncludeInLayout = False
.Position = xlLegendPositionRight
.AutoScaleFont = False
.Font.Size = 14
.Top = 25
.Left = 392
.Width = 72
.Height = 40
End With
With .ChartArea.Fill
.Visible = msoTrue
.ForeColor.SchemeColor = 33
.Solid
End With
With .SeriesCollection(1).Format.Line
.Visible = msoTrue
.ForeColor.RGB = RGB(255, 0, 0) 'red
.Transparency = 0
End With
With .SeriesCollection(2).Format.Line
.Visible = msoTrue
.ForeColor.RGB = RGB(96, 96, 96) 'grey
.Transparency = 0
End With
.HasTitle = True
With .ChartTitle
.Text = ActiveWorkbook.ActiveSheet.Cells(5, 8)
.Left = 358
.Top = 236
With .Font
.Name = "Tahoma"
.Size = 10
End With
End With
With .Axes(xlCategory)
.HasTitle = True
.AxisTitle.Text = "Position(nm)" 'X-axis title
.TickLabels.Font.Size = 10 'X-axis coordinate number size
.AxisTitle.Font.Size = 14 'X-axis title word font size
.TickMarkSpacing = 3
.TickLabelSpacing = 5
.TickLabels.NumberFormatLocal = "#,##0._);[red](#,##0.)"
.TickLabels.NumberFormatLocal = "#,##0_);[red](#,##0)"
.TickLabels.NumberFormatLocal = "0_);[red](0.)"
End With
With .Axes(xlValue)
.HasTitle = True
.AxisTitle.Text = "Strain" 'Y-aixs title
.AxisTitle.Font.Size = 14 'y-axis title word font size
'Minimum value of Y axis
.Axes(xlValue).MinimumScale = -0.005
.Axes(xlValue).TickLabels.NumberFormatLocal = "0.0%"
End With
End With
Dim thechartobj As ChartObject
Set thechartobj = ActiveWorkbook.ActiveSheet.ChartObjects(ch.Name)
Dim thechart As Chart
Set thechart = thechartobj.Chart
Dim thetextbox As Shape
Set thetextbox = thechart.Shapes.AddTextbox(msoTextOrientationHorizontal, 688, 372, 122, 20)
With thetextbox.TextFrame.Characters
.Text = ActiveSheet.Cells(6, 8)
With .Font
.Name = "tahoma"
.Size = 10
.Bold = msoTrue
End With
End With
End Sub

Macro to format charts

This is an excerpt of the code from the full macro. It operates correctly in most cases, however the color formatting is not applied when there is only one data series.
Sub fullPageLine()
Dim rng As Range
Dim cht As Object
Dim chart As chart
'Data range for the chart
'Set rng = Selection
ActiveSheet.Shapes.AddChart2(227, xlLine).Select
'Create a chart
Set cht = Selection
'Format x axis
ActiveChart.ChartArea.Select
With Selection
.Format.TextFrame2.TextRange.Font.Name = "Arial"
.Format.TextFrame2.TextRange.Font.Size = 7
End With
'Format title
ActiveChart.ChartTitle.Font.Size = 8.4
ActiveChart.ChartTitle.Left = 0
ActiveChart.ChartTitle.Top = 2
ActiveChart.ChartTitle.Select
With Selection.Format.TextFrame2.TextRange.Characters.Font
.BaselineOffset = 0
.Bold = msoTrue
.Size = 8.4
.Name = "Arial"
.Caps = msoAllCaps
End With
'Format legend
ActiveChart.Legend.Select
With Selection.Format.TextFrame2.TextRange.Font
.NameComplexScript = "Arial"
.NameFarEast = "Arial"
.Name = "Arial"
End With
Selection.Format.TextFrame2.TextRange.Font.Size = 7
'Change chart series fill color
With ActiveChart.FullSeriesCollection(1).Format.Line
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorAccent2
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = 0
.Transparency = 0
End With
With ActiveChart.FullSeriesCollection(2).Format.Line
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorText1
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = 0
.Transparency = 0
End With
With ActiveChart.FullSeriesCollection(3).Format.Line
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorBackground1
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = -0.5
.Transparency = 0
End With
The first data series should be in orange, and is whenever there are 2 or more lines on the chart. However, if it is a single line chart, it shows up in the default blue rather than orange. I am new to vba, and am aware that I need to get rid of select and activate, but am trying to get the base code to work first.
Your macro fails before assigning colors when there is only one series, because a chart with one series, by default, does not have a Legend.
Ensure that you have a legend in the chart (alternatively, use conditional logic to check whether Legend exists) before attempting to format the Legend.
Cleaned up to use object variables appropriately, and do your series formatting in a loop.
Option Explicit
Sub fullPageLine()
Dim rng As Range
Dim cht As chart
Dim i As Long, color As Long, bright As Double
Dim srs As Series
'Data range for the chart
'Set rng = Selection
Set cht = ActiveSheet.Shapes.AddChart2(227, xlLine).chart
'Format x axis
With cht.ChartArea.Format.TextFrame2.TextRange.Font
.Name = "Arial"
.Size = 7
End With
'Format title
With cht.ChartTitle
.Font.Size = 8.4
.Left = 0
.Top = 2
With .Format.TextFrame2.TextRange.Characters.Font
.BaselineOffset = 0
.Bold = msoTrue
.Size = 8.4
.Name = "Arial"
.Caps = msoAllCaps
End With
End With
'Format legend
cht.HasLegend = True
With cht.Legend.Format.TextFrame2.TextRange.Font
.NameComplexScript = "Arial"
.NameFarEast = "Arial"
.Name = "Arial"
.Size = 7
End With
' ALTERNATELY, instead of forcing the legend as per above:
'If cht.HasLegend Then
' With cht.Legend.Format.TextFrame2.TextRange.Font
' .NameComplexScript = "Arial"
' .NameFarEast = "Arial"
' .Name = "Arial"
' .Size = 7
' End With
'End If
'Change chart series fill color
For i = 1 To cht.FullSeriesCollection.Count
' Get the color based on series index
Select Case i
Case 1
color = msoThemeColorAccent2
Case 2
color = msoThemeColorText1
Case 3
color = msoThemeColorBackground1
bright = -0.5
End Select
' Assign series color formats
'## NOTE: This only works for the cases defined in the above Select statement.
Set srs = cht.FullSeriesCollection(i)
With srs.Format.Line
.Visible = msoTrue
.ForeColor.ObjectThemeColor = color
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = bright
.Transparency = 0
End With
Next
End Sub

How do I change the background image of a chart in vba?

I need to change the background image of a chart I created using vba. I tried using the .Fill command but I can't make it work. How do I do it?
This is the code I used to create the chart and it is working fine:
With myChart
.ChartStyle = 245
.SeriesCollection.NewSeries
.SeriesCollection(1).Name = ""
.HasLegend = False
.Axes(xlCategory).HasTitle = True
.Axes(xlCategory).AxisTitle.Text = "Punteggio Tecnico"
.Axes(xlValue).HasTitle = True
.Axes(xlValue).AxisTitle.Characters.Text = "Punteggio Economico"
.Axes(xlCategory).MinimumScale = 0
.Axes(xlCategory).MaximumScale = 1
.Axes(xlValue).MinimumScale = 0
.Axes(xlValue).MaximumScale = 1
.SeriesCollection(1).XValues = "=Dati2!B3:B270"
.SeriesCollection(1).Values = "=Dati2!C3:C270"
End With
If myChart is Chart variable then you want the myChart.PlotArea.Format.Fill for the area of the chart that contains the actual chart, or myChart.ChartArea.Format.Fill for the whole chart area.
The code below shows how to use it. I've commented out the colouring code that a macro recorder would supply and replaced with a basic RGB value.
Sub Test()
Dim myChart As Chart
Set myChart = Sheet1.ChartObjects("Chart 2").Chart
With myChart
With .PlotArea.Format.Fill
.ForeColor.RGB = RGB(255, 0, 0)
' .Visible = msoTrue
' .ForeColor.ObjectThemeColor = msoThemeColorAccent6
' .ForeColor.TintAndShade = 0
' .ForeColor.Brightness = 0.400000006
' .Solid
End With
With .ChartArea.Format.Fill
.ForeColor.RGB = RGB(0, 255, 0)
' .Visible = msoTrue
' .ForeColor.ObjectThemeColor = msoThemeColorAccent6
' .ForeColor.TintAndShade = 0
' .ForeColor.Brightness = 0.400000006
' .Transparency = 0
' .Solid
End With
End With
End Sub

Changing colour of a chart series based on conditions using vba

I am trying to code using vba so that a series on a chart is formatted based on certain criteria. My coding is as follows
Sub CreateChart()
Dim NPOINTS As Integer
Dim NVAL(1000) As Range, XVAL(1000) As Range, YVAL(1000) As Range
Dim Score(1000) As Range
Sheets("Scenario").Select
Range("B4").Select
NPOINTS = Worksheets("Scenario").Range(Selection, Selection.End(xlDown)).Rows.Count
Set Scenario = Worksheets("Scenario")
ActiveSheet.Shapes.AddChart2(240, xlXYScatter).Select
NVAL0 = "B3"
XVAL0 = "C3"
YVAL0 = "D3"
SCORE0 = "E3"
For i = 1 To NPOINTS
Set Score(i) = Cells(Range(SCORE0).Offset(i, 0).Row, Range(SCORE0).Column)
Set NVAL(i) = Cells(Range(NVAL0).Offset(i, 0).Row, Range(NVAL0).Column)
Set XVAL(i) = Cells(Range(XVAL0).Offset(i, 0).Row, Range(XVAL0).Column)
Set YVAL(i) = Cells(Range(YVAL0).Offset(i, 0).Row, Range(YVAL0).Column)
Scorei = Score(i).Value
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(i).Name = NVAL(i)
ActiveChart.FullSeriesCollection(i).XValues = XVAL(i)
ActiveChart.FullSeriesCollection(i).Values = YVAL(i)
If Scorei <= 10 >= 0 Then
ActiveChart.SeriesCollection(i).Points.Interior.Colour = _
RGB(0, 255, 0) 'Green
ElseIf Scorei <= 30 >= 11 Then
ActiveChart.SeriesCollection(i).Points.Interior.Colour = _
RGB(0, 255, 0) 'Green
ElseIf Scorei <= 60 >= 31 Then
ActiveChart.SeriesCollection(i).Points.Interior.Colour = _
RGB(0, 255, 0) 'Green
ElseIf Scorei <= 100 >= 61 Then
ActiveChart.SeriesCollection(i).Points.Interior.Colour = _
RGB(0, 255, 0) 'Green
Else
MsgBox "ERROR :- Score out of range"
End If
Next
With ActiveChart
'chart name
.HasTitle = False
'X axis name
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "INFLUENCE"
'y-axis name
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "IMPORTANCE"
.SetElement (msoElementLegendRight)
.Location Where:=xlLocationAsNewSheet, Name:="Priority Chart"
End With
End Sub
Unfortunately when I run it, it fails with "Object doesn't support this property or method and then when I press Debug it highlights the following line
ActiveChart.SeriesCollection(i).Points.Interior.Colour = _
RGB(0, 255, 0) 'Green
Where am I going wrong?
I appreciate any help.
just
ActiveChart.SeriesCollection(i).format.Fill.ForeColor.RGB =RGB(0, 255, 0)
The .Points() is a collection.
You will need to cycle through all its elements and change the color one by one.
The left most point is .Points(1), the right most point is .Points.count
as per: Change the Point Color in chart excel VBA
Also there is no such thing as interior colour for points.
There are 4 relevant options as per: https://msdn.microsoft.com/en-us/vba/excel-vba/articles/point-object-excel
MarkerBackgroundColor
MarkerBackgroundColorIndex
MarkerForegroundColor
MarkerForegroundColorIndex
As per comment from Jon Peltier it is not recommended to make use of the colorindex as this is a legacy from excel <2003

Resources