如何将Excel或PowerPoint堆积的条形图设置为不显示#N / As? 我有这样的数据
日期销售网
1月12日1.5 .5
2月12日2.6 1.5
我在数据范围内有N?As,因为它们可能在某个时刻获得数据,因此是动态的。 我不想使用偏移量,因为它在Powerpoint中创建的图表中不能很好地工作。 有超过125张幻灯片和100张图表,因此手动更改并不好。 我在Powerpoint中创建图表,然后添加到图表后面的数据页面的链接。更新很好,但在打破所有这些链接后(我有一个宏), 名为范围的偏移量不会更新,因为公式需要工作表名称(如Sheet1!),但Powerpoint将其称为“Microsoft PowerPoint中的图表”。
我希望我解释得这么多。 感谢
答案 0 :(得分:0)
由于我无法使用偏移或命名范围达到良好效果,因此我创建了此PPT宏来重置数据中的数据范围 1)任何不要绘制的数据行的x轴值为零而不是#N / A. 2)在数据表的F1中必须使用countif not = 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