Aggiornare automaticamente dati pivot
Hai un problema con Excel? 
Aggiornare automaticamente dati pivot
di Robort data: 06/02/2014 08:53:42
Buon giorno a tutti.
C'è un modo per poter automatizzare i dati di una pivot? Attualmente faccio l'inserimento, salvo ed esco dal file in questione. Lo riapro e vedo i dati aggiornati. Oppure devo cliccare col tasto dx sopra ai dati e selezionare aggiorna. Esiste un modo per aggiornare tali dati subito dopo che sono stati immessi? Grazie.
di mb data: 06/02/2014 09:11:28
Ciao premesso che non è farina del mio sacco ma di un esperto che è Gr...an
io la utilizzo al mattino per aggiornarmi dei dati dei magazzini
le colonne hanno un'intestazione e vanno da A a K
vedi se riesci ad adeguarla alle tue esigenze
buona giornata
Sub Crea_Pivotta_2()
Dim wb As Workbook
Dim ws As Worksheet
Dim oPvtCch As PivotCache
Dim oPvtTbl As PivotTable
Dim rng As Range
Dim r As Double
Set wb = ThisWorkbook
Set ws = wb.Worksheets("Foglio1")
r = ws.Cells(Rows.Count, 1).End(xlUp).Row 'occhio al riferimento di colonna
Set rng = ws.Range("A1:k" & r)
On Error Resume Next
Set oPvtTbl = ws.PivotTables("Pivotta")
If Not oPvtTbl Is Nothing Then
Set oPvtCch = wb.PivotCaches.Create(SourceType:=xlDatabase, SourceData:="Foglio1!R1C1:R" & r & "C11", Version:=xlPivotTableVersion14) 'come sopra
oPvtTbl.ChangePivotCache oPvtCch 'sostituisce la cache della tabella, la aggiorna
Else
Set oPvtCch = wb.PivotCaches.Create(SourceType:=xlDatabase, SourceData:="Foglio1!R1C1:R" & r & "C11") 'crea cache per tabella dal range
Set oPvtTbl = oPvtCch.CreatePivotTable(ws.Cells(2, 14)) 'crea pivot in nuovo foglio
With oPvtTbl
.Name = "Pivotta"
.PivotFields(2).Orientation = xlRowField
.PivotFields(2).Position = 1
.AddDataField .PivotFields(11), "Tuo nome per la somma", xlSum
End With
End If
Set wb = Nothing
Set ws = Nothing
Set rng = Nothing
Set oPvtCch = Nothing
Set oPvtTbl = Nothing
End Sub
|
di Vecchio Frac data: 06/02/2014 21:46:25
cit. "premesso che non è farina del mio sacco ma di un esperto che è Gr...an "
---> Diciamolo pure per esteso: "Grograman"
A ciascuno il suo ^_^
di Grograman data: 07/02/2014 09:50:28
Così mi fate arrossire
Premesso che non mi è chiara la domanda, nel senso che non ha specificato se deve aggiornare solo la pivot, o modificarne il range di dati includendo nuove righe, a seguire un piccolo (e molto blando) componente aggiuntivo che mi sono creato per aggiornare tutte le pivot di un file, lo tengo nel ribbon in una scheda personalizzata insieme ad altri componenti aggiuntivi.
Sub Cache_Pivot()
Dim wb As Workbook
Dim ws As Worksheet
On Error Resume Next
Dim pvtTbl As PivotTable
Set wb = ActiveWorkbook
Set ws = wb.ActiveSheet
For Each ws In wb.Worksheets
For Each pvtTbl In ws.PivotTables
pvtTbl.PivotCache.Refresh
Next pvtTbl
Next ws
Set ws = Nothing
Set wb = Nothing
End Sub
|
di Grograman data: 07/02/2014 09:51:45
Ah il set ws = activesheet è ovviamente un refuso mi sono accorto adesso che è perfettamente inutile...
di mb data: 07/02/2014 10:39:25
buongiorno e ben tornato v.f
ho scritto solo le iniziali e le finali del nickname x non offendere nessuno degli altri grandi del forum
grazie per l'annotazione lo terrò presente per i prossimi interventi
buona giornata
di Grograman (utente non iscritto) data: 07/02/2014 14:52:34
Già che ci siamo, ho notato che dichiari il Range dei dati, ma poi non lo usi nella creazione della pivot
Option Explicit
Sub Crea_Pivotta_2()
Dim wb As Workbook
Dim ws As Worksheet
Dim oPvtCch As PivotCache
Dim oPvtTbl As PivotTable
Dim rng As Range
Dim r As Long
Set wb = ThisWorkbook
Set ws = wb.Worksheets("Foglio1")
r = ws.Cells(Rows.Count, 1).End(xlUp).Row 'occhio al riferimento di colonna
Set rng = ws.Range("A1:k" & r) 'perchè dichiararlo se non lo usi? vedi sotto
On Error Resume Next
Set oPvtTbl = ws.PivotTables("Pivotta")
If Not oPvtTbl Is Nothing Then
Set oPvtCch = wb.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=rng.Address, Version:=xlPivotTableVersion14) 'ecco usato il range
oPvtTbl.ChangePivotCache oPvtCch 'sostituisce la cache della tabella, la aggiorna
Else
Set oPvtCch = wb.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=rng.Address) 'crea cache per tabella dal range
Set oPvtTbl = oPvtCch.CreatePivotTable(ws.Cells(2, 14)) 'crea pivot in nuovo foglio
With oPvtTbl
.Name = "Pivotta"
.PivotFields(2).Orientation = xlRowField
.PivotFields(2).Position = 1
.AddDataField .PivotFields(11), "Tuo nome per la somma", xlSum
End With
End If
Set wb = Nothing
Set ws = Nothing
Set rng = Nothing
Set oPvtCch = Nothing
Set oPvtTbl = Nothing
End Sub
|
di mb data: 07/02/2014 16:01:31
grazie Grograman
me lo avevi già detto un'altra volta ma mi sono dimenticato di fare la correzione
ti ringrazio come sempre per l'aiuto
buon pomeriggio
Vuoi Approfondire?