|
老师chart code
如何让堆积图里"市占率"变成折线图(副坐标),请问各位导师要怎么修改代码
Sub Chart1()
Dim ws As Worksheet
Dim cht As Chart
Dim co As ChartObject
Dim rng As Range
Dim i As Integer
Set ws = ThisWorkbook.Sheets("SHEET2")
Set co = ws.ChartObjects.Add(Left:=50, Width:=600, Top:=50, Height:=300)
Set cht = co.Chart
cht.SetSourceData ws.Range("B3:n3"), xlColumns
Dim seriesIndex As Integer
seriesIndex = 1
For i = 4 To ws.Range("A" & ws.Rows.Count).End(xlUp).Row
If Not IsEmpty(ws.Range("A" & i)) Then
cht.SeriesCollection.NewSeries
cht.SeriesCollection(seriesIndex).Name = ws.Range("A" & i)
Set rng = ws.Range(ws.Range("B" & i), ws.Range("M" & i))
cht.SeriesCollection(seriesIndex).Values = rng
If ws.Range("A" & i) = "市占率" Then
cht.SeriesCollection(seriesIndex).ChartType = xlLineMarkers
cht.SeriesCollection(seriesIndex).AxisGroup = xlSecondary
cht.SeriesCollection(seriesIndex).HasDataLabels = True
cht.SeriesCollection(seriesIndex).DataLabels.NumberFormat = "0.0%"
Else
cht.SeriesCollection(seriesIndex).ChartType = xlColumnStacked
End If
seriesIndex = seriesIndex + 1
Else
End If
Next i
End Sub
|
|