TABELLA PIVOT CAMBIO NOME FOGLIO
Hai un problema con Excel? 
TABELLA PIVOT CAMBIO NOME FOGLIO
di maxp72 data: 21/04/2015 11:08:38
Salve devo creare una pivot con la stessa struttura su piu' fogli differenti
come faccio per modifcare il nome del foglio da selezionare?
ho provato con la macro sotto a sostituire il nome del foglio con una variabile ma risulta che la sintassi non sia corretta...
mi sapreste dire qual'e' l'errore?
grazie
Dim lastrow As Long
Dim ROW_PIVOT As String
Dim foglio As String
Range("A1").Select
lastrow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
foglio = ActiveSheet.Name '& "!"
ROW_PIVOT = lastrow + 5
Range("A" & lastrow + 5).Select
'ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"001450301!R1C1:R" & ROW_PIVOT & "c9", Version:=xlPivotTableVersion10).CreatePivotTable _
TableDestination:="001450301!R" & ROW_PIVOT & "C1", TableName:="Tabella_pivot2", _
DefaultVersion:=xlPivotTableVersion10
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, _
SourceData:= " & foglio "!R1C1:R" & ROW_PIVOT & "C9", Version:=xlPivotTableVersion10).CreatePivotTable _
TableDestination:=" & foglio & "!R" & ROW_PIVOT & "C1", TableName:="Tabella_pivot2", _
DefaultVersion:=xlPivotTableVersion10 |
di maxp72 data: 22/04/2015 10:41:13
ok risolto ho trovato googlando il codice sotto, ho aggiunto il nome della tabella ("PivotTable1"), ed una variabile per il nome del foglio e adesso riesco a creare la stessa struttura su tutti i fogli del mio ciclo .
grazie lo stesso.
p.s. ho gia' pronto un altro quesito pero'...
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("Fogliodacambiare")
Set ws = wb.Worksheets(ActiveSheet.Name)
r = ws.Cells(Rows.Count, 3).End(xlUp).Row 'occhio al riferimento di colonna
Set rng = ws.Range("C1:C" & r) 'idem come sopra, espandi il range
Set oPvtCch = wb.PivotCaches.Add(SourceType:=xlDatabase, SourceData:=rng)
Set oPvtTbl = oPvtCch.CreatePivotTable(TableDestination:=ws.Cells(r + 5, 1), TableName:="PivotTable1")
oPvtTbl.Parent.PivotTableWizard TableDestination:=oPvtTbl.Parent.Cells(3, 1) 'sposta la pivot dove vuoi che inizi |
Vuoi Approfondire?