如何创build从多个工作表中抽取数据的Excel图表?

我有每月销售数字存储在单独的工作表。 我想创造一个每月多个产品的销售情节。 每个产品将在同一个图表上用不同的颜色线表示,每个月沿x轴运行。

创build单张折线图的最佳方式是从多张纸上的相同单元格拉出来的?

使用图表向导。

在步骤2中,有一个标签为“系列”的标签。 这个标签上有3个字段和一个列表框。 列表框显示了您已经包含在图表中的不同系列。 每个系列都有“名称”字段和特定于该系列的“值”字段。 最后一个字段是“类别(X)轴标签”字段,这对所有系列都是通用的。

点击列表框下方的“添加”button。 这将为您的列表框添加一个空白的系列。 请注意,当您在列表框中突出显示一个系列时,“名称”和“值”的值会更改。

select你的新系列。

右侧的每个字段都有一个图标。 该图标允许您select工作簿中的单元格以从中提取数据。 当您单击它时,向导会暂时隐藏自己(除了正在使用的字段),允许您与工作簿进行交互。

在工作簿中select适当的工作表,然后select包含要在图表中显示的数据的字段。 可以单击该字段右侧的button来取消隐藏向导。

希望有所帮助。

编辑:上面适用于2003年和之前。 对于2007年,当select图表时,您应该可以使用function区“devise”选项卡上的“select数据”选项执行类似操作。 这会打开一个对话框,列出图表的系列。 您可以像在Excel 2003中那样select系列,但是您必须使用“添加”和“编辑”button来定义自定义系列。

以下是Excel 2010中可能有用的一些代码。 它有几个细节(比如过滤来自标题的错误编码字符),但它被devise成从具有绝对数据和基于百分比数据的四维数据创build多个多系列图。 修改它你喜欢的方式:

Sub createAllGraphs() Const chartWidth As Integer = 260 Const chartHeight As Integer = 200 If Sheets.Count = 1 Then Sheets.Add , Sheets(1) Sheets(2).Name = "AllCharts" ElseIf Sheets("AllCharts").ChartObjects.Count > 0 Then Sheets("AllCharts").ChartObjects.Delete End If Dim c As Variant Dim c2 As Variant Dim cs As Object Set cs = Sheets("AllCharts") Dim s As Object Set s = Sheets(1) Dim i As Integer Dim chartX As Integer Dim chartY As Integer Dim r As Integer r = 2 Dim curA As String curA = s.Range("A" & r) Dim curB As String Dim curC As String Dim startR As Integer startR = 2 Dim lastTime As Boolean lastTime = False Do While s.Range("A" & r) <> "" If curC <> s.Range("C" & r) Then If r <> 2 Then seriesAdd: c.SeriesCollection.Add s.Range("D" & startR & ":E" & (r - 1)), , False, True c.SeriesCollection(c.SeriesCollection.Count).Name = Replace(s.Range("C" & startR), "Â", "") c.SeriesCollection(c.SeriesCollection.Count).XValues = "='" & s.Name & "'!$D$" & startR & ":$D$" & (r - 1) c.SeriesCollection(c.SeriesCollection.Count).Values = "='" & s.Name & "'!$E$" & startR & ":$E$" & (r - 1) c.SeriesCollection(c.SeriesCollection.Count).HasErrorBars = True c.SeriesCollection(c.SeriesCollection.Count).ErrorBars.Select c.SeriesCollection(c.SeriesCollection.Count).ErrorBar Direction:=xlY, Include:=xlBoth, Type:=xlCustom, Amount:="='" & s.Name & "'!$F$" & startR & ":$F$" & (r - 1), minusvalues:="='" & s.Name & "'!$F$" & startR & ":$F$" & (r - 1) c.SeriesCollection(c.SeriesCollection.Count).ErrorBar Direction:=xlX, Include:=xlBoth, Type:=xlFixedValue, Amount:=0 c2.SeriesCollection.Add s.Range("D" & startR & ":D" & (r - 1) & ",G" & startR & ":G" & (r - 1)), , False, True c2.SeriesCollection(c2.SeriesCollection.Count).Name = Replace(s.Range("C" & startR), "Â", "") c2.SeriesCollection(c2.SeriesCollection.Count).XValues = "='" & s.Name & "'!$D$" & startR & ":$D$" & (r - 1) c2.SeriesCollection(c2.SeriesCollection.Count).Values = "='" & s.Name & "'!$G$" & startR & ":$G$" & (r - 1) c2.SeriesCollection(c2.SeriesCollection.Count).HasErrorBars = True c2.SeriesCollection(c2.SeriesCollection.Count).ErrorBars.Select c2.SeriesCollection(c2.SeriesCollection.Count).ErrorBar Direction:=xlY, Include:=xlBoth, Type:=xlCustom, Amount:="='" & s.Name & "'!$H$" & startR & ":$H$" & (r - 1), minusvalues:="='" & s.Name & "'!$H$" & startR & ":$H$" & (r - 1) c2.SeriesCollection(c2.SeriesCollection.Count).ErrorBar Direction:=xlX, Include:=xlBoth, Type:=xlFixedValue, Amount:=0 If lastTime = True Then GoTo postLoop End If If curB <> s.Range("B" & r).Value Then If curA <> s.Range("A" & r).Value Then chartX = chartX + chartWidth * 2 chartY = 0 curA = s.Range("A" & r) End If Set c = cs.ChartObjects.Add(chartX, chartY, chartWidth, chartHeight) Set c = c.Chart c.ChartWizard , xlXYScatterSmooth, , , , , True, Replace(s.Range("B" & r), "Â", "") & " " & s.Range("A" & r), s.Range("D1"), s.Range("E1") Set c2 = cs.ChartObjects.Add(chartX + chartWidth, chartY, chartWidth, chartHeight) Set c2 = c2.Chart c2.ChartWizard , xlXYScatterSmooth, , , , , True, Replace(s.Range("B" & r), "Â", "") & " " & s.Range("A" & r) & " (%)", s.Range("D1"), s.Range("G1") chartY = chartY + chartHeight curB = s.Range("B" & r) curC = s.Range("C" & r) End If curC = s.Range("C" & r) startR = r End If If s.Range("A" & r) <> "" Then oneMoreTime = False ' end the loop for real this time r = r + 1 Loop lastTime = True GoTo seriesAdd postLoop: cs.Activate End Sub 

2007:function更加强大:=)要在图表中添加新的系列,请执行以下操作:select图表,然后单击function区上的图表工具中的devise,在devisefunction区上select数据组中的“select数据”,然后添加button添加新的系列。

希望这会有所帮助。