|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Mar 2002
Città: Bari
Messaggi: 3084
|
[VBA] Domanda da niubbo su macro
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, in questa macro: Codice:
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
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.
__________________
AMD Ryzen7 1700 - MSI X370 Gaming Pro Carbon - Corsair Vengeance RGB - MSI GTX-1080 Armor OC - LG 27UD68 - Corsair RM650i - Sharkoon M25-W - Samsung 850 evo - Western Digital Caviar Green 2TB |
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: Jul 2007
Messaggi: 1092
|
Prova un codice di questo genere:
Codice:
Sub grafici()
For Each foglio In Application.Worksheets
foglio.Activate
For Each grafico In ActiveSheet.ChartObjects
ActiveSheet.ChartObjects(grafico.Name).Activate
ActiveChart.SeriesCollection(1).DataLabels.Select
Selection.NumberFormat = " 0.0%;;"
Next grafico
Next foglio
End Sub
|
|
|
|
|
|
#3 | |
|
Senior Member
Iscritto dal: Mar 2002
Città: Bari
Messaggi: 3084
|
Quote:
Credo che l'errore sia in Codice:
Selection.NumberFormat = " 0.0%;;"
__________________
AMD Ryzen7 1700 - MSI X370 Gaming Pro Carbon - Corsair Vengeance RGB - MSI GTX-1080 Armor OC - LG 27UD68 - Corsair RM650i - Sharkoon M25-W - Samsung 850 evo - Western Digital Caviar Green 2TB |
|
|
|
|
|
|
#4 |
|
Senior Member
Iscritto dal: Mar 2002
Città: Bari
Messaggi: 3084
|
Dimenticavo, i valori delle etichette sono dei valori adimensionali, non percentuali.
__________________
AMD Ryzen7 1700 - MSI X370 Gaming Pro Carbon - Corsair Vengeance RGB - MSI GTX-1080 Armor OC - LG 27UD68 - Corsair RM650i - Sharkoon M25-W - Samsung 850 evo - Western Digital Caviar Green 2TB |
|
|
|
|
|
#5 |
|
Senior Member
Iscritto dal: Jul 2007
Messaggi: 1092
|
Se i valori sono assoluti e non percentuali sostituisci come hai giustamente intuito
Selection.NumberFormat = " 0.0%;;" con Selection.NumberFormat = "*??" |
|
|
|
|
|
#6 |
|
Senior Member
Iscritto dal: Mar 2002
Città: Bari
Messaggi: 3084
|
Ora provo.
__________________
AMD Ryzen7 1700 - MSI X370 Gaming Pro Carbon - Corsair Vengeance RGB - MSI GTX-1080 Armor OC - LG 27UD68 - Corsair RM650i - Sharkoon M25-W - Samsung 850 evo - Western Digital Caviar Green 2TB |
|
|
|
|
|
#7 |
|
Senior Member
Iscritto dal: Mar 2002
Città: Bari
Messaggi: 3084
|
Non va.
Perchè, penso, ho spesso valori tipo 0.65 o 0.04 e simili...
__________________
AMD Ryzen7 1700 - MSI X370 Gaming Pro Carbon - Corsair Vengeance RGB - MSI GTX-1080 Armor OC - LG 27UD68 - Corsair RM650i - Sharkoon M25-W - Samsung 850 evo - Western Digital Caviar Green 2TB |
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 03:19.




















