2012-12-04 35 views
0

如何获取Excel或PowerPoint堆叠的条形图以不显示#N/A? 我有这样Excel/Powerpoint不使用偏移量的动态条形图

日期销售网络

一月-12 1.5 0.5

二月-12 2.6 1.5

N/A#N/A#N/A

数据

N/A#N/A#N/A

我有N?在数据的范围内,因为它们可能会在某个点获得数据,因此Dynamic。 我不想使用偏移量,因为它在Powerpoint中创建的图表中效果不佳。 有超过125张幻灯片和100多张图表,因此手动更改效果不佳。 我在Powerpoint中创建图表,然后将链接添加到图表后面的数据页面。更新很好,但打破所有这些链接后(我有一个这样的宏), 由于公式需要工作表名称(如Sheet1!),所以名称范围的偏移量不会更新,但Powerpoint称它为'Chart in Microsoft PowerPoint ”。

我希望我已经解释过了。 由于

回答

0

既然不能使用偏移或命名范围,效果良好,我创建这个PPT宏重置数据范围在我的数据 1)数据的任何行不是要被绘制具有x轴和零值不#N /中数据表的F1甲 2)具有数行以图表的数量,使用COUNTIF不是0 3)命名图表中,我使用= StackedBar1 运行宏

如果有人有一个更简单的解决方案,请让我知道。

Sub C_SetSourceData_StackedBar() 
Dim s As Slide 
Dim shp As Shape 

For Each s In ActivePresentation.Slides 'moves through all slides in presentation 
For Each shp In s.Shapes     'moves through each shape on slide 
    If shp.Name = "StackedBar1" Then  ' stacked bar chart that needs source data updated is named this 

     Set c = shp.Chart     'set c to the chart object 

     Dim data As ChartData 
     Set data = c.ChartData    'sets data to the chartdata behind the chart 
     data.Activate      'need to activate the chartdat(excel sheet) 

      'in cell F1 the formula =countif(A1:A50,"<>0") this counts the rows that are not zero 
     x = data.Workbook.Worksheets(1).Range("F1").Value 'gets the last row number of data not zero 
     Let rng = "Sheet1!$A$1:$E$" & x     ' creates the source range as a string 

     c.SetSourceData (rng)        ' Sets the new source data range 

     data.Workbook.Close         ' Close the chartdata workbook 
    End If 
Next shp 
Next s 
End Sub