我正在尝试使用VBA在Excel上创建图表。但是,x轴始终显示行号而不是行中的值。这是我目前的代码。难道我做错了什么?
虽然y轴是正确的If CheckBox4.Value = False Then
If CheckBox1.Value = True Then 'S11 S22
ActiveSheet.Shapes.AddChart.Select
With ActiveChart
.HasTitle = True
.ChartTitle.Text = "S11 & S22"
.ChartType = xlXYScatterLinesNoMarkers
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Frequency/GHz"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "/dB"
.SetSourceData Source:=Range("B2:T5")
Do Until .SeriesCollection.Count = 0
.SeriesCollection(1).Delete
Loop
.SeriesCollection.NewSeries
.SeriesCollection(1).Name = "S11"
.SeriesCollection(1).XValues = Range("A9:A" & j)
.SeriesCollection(1).Values = Range("B9:B" & j)
.SetElement (msoElementPrimaryCategoryGridLinesMinorMajor)
.SetElement (msoElementPrimaryValueGridLinesMinorMajor)
' .SetElement (msoElementPrimaryCategoryAxisLogScale)
.SeriesCollection.NewSeries
.SeriesCollection(2).Name = "S22"
.SeriesCollection(2).XValues = Range("A9:A" & j)
.SeriesCollection(2).Values = Range("H9:H" & j)
With .Parent
.Height = 300
.Width = 500
.Top = 50
.Left = 600
End With
End With
End If
先谢谢你们!
答案 0 :(得分:1)
尝试重新安装
.SeriesCollection(1).XValues = Range("A9:A" & j)
使用:
.SeriesCollection(1).XValues = "=" & Range("A9:A" & j).Address(False, False, xlA1, xlExternal)