2012-12-04 37 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