【发布时间】:2020-12-03 20:52:05
【问题描述】:
我正在 Excel 中创建一个图表。我想要一个不同版本的图表,但不确定它会被调用什么,或者我是否需要在代码中做其他事情。
这里有两个问题。
- 我想要彩色版的图表。我是否使用 xlBarClustered 以外的其他内容?
- 注意左侧的标签。我希望这些图例位于右侧,但似乎我的图例是 F 列的标题。
我有两张图片:
这是当前代码:
Sub CreateChart()
'
' CreateChart Macro
' Creates a chart in one worksheet
' Want the range to start with E1, go to the right and down.
' first row is a header row.
'
Dim rng As Range
Dim cht As Chart
'Set cht = Sheets("Chart 1")
'Set cht = ActiveChart
Set cht = ActiveSheet.Shapes.AddChart2.Chart
Set rng = ActiveSheet.Range("E1:F5")
cht.SetSourceData Source:=rng
cht.ChartType = xlBarClustered
cht.Axes(xlValue, xlPrimary).HasTitle = True
cht.Axes(xlValue, xlPrimary).AxisTitle.Text = "Percent"
cht.HasTitle = True
cht.ChartTitle.Text = Cells(2, 3).Value
cht.ChartTitle.Font.Bold = True
cht.ChartTitle.Font.Name = "Arial"
cht.HasLegend = True
cht.Legend.Position = xlLegendPositionRight
End Sub
【问题讨论】:
-
图片无法发布。有人对我如何显示图像有任何建议吗?
-
我想用它在许多工作表中创建图表。我录制了一个宏来创建我想要制作的图表版本。 -- 为什么我不能在我在第一条消息中发布的代码中使用“ActiveChart.”,就像宏记录一样?如果你能给我指出一个很好的资源来快速学习 VB 中的图表,那也很棒。我找到了很多东西,但最终我要查找的几乎所有内容都在不同的页面上。是否有很好的单一图表信息来源。