Salvatopo
31-07-2008, 17:52
Ciao a tutti.
Premetto che è la prima volta in assoluto che utilizzo il VBA
Detto questo: mi trovavo nella necessità di dover, in automatico, eliminare le etichette a valore 0 (zero) in una serie di fogli di excel con dei grafici a torta e mi sono imbattuto, sul sito microsoft (http://support.microsoft.com/kb/142132/it), in questa macro:
Sub Auto_Open()
' Change the "Sheet1" to the sheet with your data on it.
Worksheets("Sheet1").OnCalculate = "ClearLabels"
End Sub
Sub Auto_Close()
Worksheets("Sheet1").OnCalculate = ""
End Sub
Sub ClearLabels()
' Change the "Sheet1" to the Sheet with your chart on it and
' "Chart 1" to the name of your chart.
Worksheets("Sheet1").ChartObjects("Chart 1").Chart.ApplyDataLabels _
Type:=xlShowPercent
' Note: In preceding statement, use Type:=xlShowPercent for charts
' with just percents, if there are none. Use
' Type:=xlShowLabelAndPercent instead for charts with both, Labels
' and Percents, if there are none.
For Each X In Worksheets("Sheet1").ChartObjects("Chart 1"). _
Chart.SeriesCollection(1).Points
' Use the following two lines for charts with just percents.
If InStr(X.DataLabel.Text, "0%") > 0 _
And Len(X.DataLabel.Text) = 2 Then
' Use the following line instead for charts with labels and
' percents.
' If InStr(x.DataLabel.Text, Chr(10) & "0%") > 0 Then
X.DataLabel.Delete
End If
Next
End Sub
Ora: ogni file contiene 3 fogli, chiamati rispettivamente "Torte IF", "Torte IG" e "Torte IDM" i quali a loro volta contengono ognuno 6 grafici, chiamati "grafico 1", "grafico 2", ecc...
Il mio problema è: come faccio a
1) Modificare la macro affinchè processi i 3 fogli e i 18 grafici in automatico
2) Processare tutti i 47 files che contengono le stesse torte, ma con dati diversi?
P.S.
Ovviamente se sostituisco a mano "Sheet 1" con, ad es. "Torte IG" e "Chart 1" con "Grafico 1" tutto funziona, ma il problema è, appunto, farlo fare in automatico, magari mettendo un tastino sulla barra di excel.
Premetto che è la prima volta in assoluto che utilizzo il VBA
Detto questo: mi trovavo nella necessità di dover, in automatico, eliminare le etichette a valore 0 (zero) in una serie di fogli di excel con dei grafici a torta e mi sono imbattuto, sul sito microsoft (http://support.microsoft.com/kb/142132/it), in questa macro:
Sub Auto_Open()
' Change the "Sheet1" to the sheet with your data on it.
Worksheets("Sheet1").OnCalculate = "ClearLabels"
End Sub
Sub Auto_Close()
Worksheets("Sheet1").OnCalculate = ""
End Sub
Sub ClearLabels()
' Change the "Sheet1" to the Sheet with your chart on it and
' "Chart 1" to the name of your chart.
Worksheets("Sheet1").ChartObjects("Chart 1").Chart.ApplyDataLabels _
Type:=xlShowPercent
' Note: In preceding statement, use Type:=xlShowPercent for charts
' with just percents, if there are none. Use
' Type:=xlShowLabelAndPercent instead for charts with both, Labels
' and Percents, if there are none.
For Each X In Worksheets("Sheet1").ChartObjects("Chart 1"). _
Chart.SeriesCollection(1).Points
' Use the following two lines for charts with just percents.
If InStr(X.DataLabel.Text, "0%") > 0 _
And Len(X.DataLabel.Text) = 2 Then
' Use the following line instead for charts with labels and
' percents.
' If InStr(x.DataLabel.Text, Chr(10) & "0%") > 0 Then
X.DataLabel.Delete
End If
Next
End Sub
Ora: ogni file contiene 3 fogli, chiamati rispettivamente "Torte IF", "Torte IG" e "Torte IDM" i quali a loro volta contengono ognuno 6 grafici, chiamati "grafico 1", "grafico 2", ecc...
Il mio problema è: come faccio a
1) Modificare la macro affinchè processi i 3 fogli e i 18 grafici in automatico
2) Processare tutti i 47 files che contengono le stesse torte, ma con dati diversi?
P.S.
Ovviamente se sostituisco a mano "Sheet 1" con, ad es. "Torte IG" e "Chart 1" con "Grafico 1" tutto funziona, ma il problema è, appunto, farlo fare in automatico, magari mettendo un tastino sulla barra di excel.