FaridWahidi
Board Regular
- Joined
- Apr 22, 2014
- Messages
- 93
I am writing a macro to create multiple Line Makers Chart for monthly data in the same worksheets. The 1st & 3rd chart working fine but the 2nd chart parameter is wrongly populated to 7 series collection rather than 3 series collection. (Accurate Parameter)
Previously I have used .SetSourceData Source:=rng, it working fine but will be wrongly populated if the monthly data less than 3 months whereby rows more than columns.
Then, I have tried to add series one by one using .SeriesCollection.Add Source:=rng.
Here is the download link to my attachment
https://app.box.com/s/di3fneqtgpfr9xj35yrz
Nothing wrong with this code but why the 2nd chart parameter wrongly populated. Can anyone help me?
Previously I have used .SetSourceData Source:=rng, it working fine but will be wrongly populated if the monthly data less than 3 months whereby rows more than columns.
Then, I have tried to add series one by one using .SeriesCollection.Add Source:=rng.
Here is the download link to my attachment
https://app.box.com/s/di3fneqtgpfr9xj35yrz
Nothing wrong with this code but why the 2nd chart parameter wrongly populated. Can anyone help me?
Code:
With ws
LastRow = .Range("B14").End(xlUp).Row
Set rng_1a = .Range("A2:B" & LastRow)
Set rng_1b = .Range("C2:C" & LastRow)
Set rng_1c = .Range("D2:D" & LastRow)
ShName = .Name
End With
[COLOR=#008000]'Count number of months[/COLOR]
Mon = ws.Range("B2:B" & ws.Range("B14").End(xlUp).Row).count
If Mon = 1 Then
RPM = "BB Score Trend (Jan" & "'" & Format(Now(), "YY") & ")"
ElseIf Mon >= 2 And Mon <= 11 Then
RPM = "BB Score Trend (Jan - " & MonthName(Mon, True) & "'" & Format(Now(), "YY") & ")"
ElseIf Mon = 12 Then
RPM = "BB Score Trend (Jan - " & MonthName(Mon, True) & "'" & Format(DateSerial(Year(Date) - 1, Month(Date), 1), "YY") & ")"
End If
ws.Select
Charts.Add
With ActiveChart
.ChartType = xlLineMarkers
.HasTitle = True
.ChartTitle.Text = RPM
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Month" [COLOR=#008000]'X axis name[/COLOR]
.Axes(xlCategory, xlPrimary).AxisTitle.Left = 635
.Axes(xlCategory, xlPrimary).AxisTitle.Top = 380
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).HasMajorGridlines = False
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Scoring" [COLOR=#008000]'y-axis name[/COLOR]
.Axes(xlValue, xlPrimary).AxisTitle.Orientation = xlHorizontal
.Axes(xlValue, xlPrimary).AxisTitle.Top = xlUpward
.Axes(xlValue, xlPrimary).AxisTitle.Top = 10
.Axes(xlValue, xlPrimary).AxisTitle.Left = 60
.SeriesCollection.Add Source:=rng_1a
.SeriesCollection.Add Source:=rng_1b
.SeriesCollection.Add Source:=rng_1c
.Location Where:=xlLocationAsObject, Name:=ShName
End With
Last edited: