finaljustice
Board Regular
- Joined
- Oct 6, 2010
- Messages
- 175
Hello, i've never used a dynamic table and a collegue of mine asked me to work on a workbook of his. I noticed he would have to do some repetitive things and decided to make a macro (making our jobs easier).
Basically its a code that copies the a template worksheet named 300000 and copies and renames the sheet following a list. Creating the sheets and renaming them I was able to do.
Now inside the sheets there are 3 dynamic tabels, where i have to "apply a filter" with this new sheets name. I tried recording the macro and got this. (its portuguese but "TABELA DINÂMICA1" means "Dynamic Table1"; "CENTRO DE CUSTOS" means "Costs Centers").
Any ideas how I can change this? I will always be making the
.PivotItems("300000").Visible = False
.PivotItems("nomesheet").Visible = True (applying the new "filter" to the same cost center as the newly generated sheet.
I would expect the end code to look something like this ( I just don't know the correct way to code it):
Thank your for your attention and help.
Your sincerely,
final
Basically its a code that copies the a template worksheet named 300000 and copies and renames the sheet following a list. Creating the sheets and renaming them I was able to do.
Code:
Sub centrocustosheets()
Application.ScreenUpdating = False
Sheets(2).Select
Range("A3").Select
contar = Range(ActiveCell, ActiveCell.End(xlDown)).Count
ActiveCell.Offset(1, 0).Select
Do While ActiveCell <> Empty
nomesheet = ActiveCell.Text
Sheets("300000").Select
Sheets("300000").Copy After:=Sheets(7)
Sheets("300000 (2)").Select
Sheets("300000 (2)").Name = nomesheet
Sheets(2).Select
ActiveCell.Offset(1, 0).Select
Loop
Application.ScreenUpdating = True
End Sub
Now inside the sheets there are 3 dynamic tabels, where i have to "apply a filter" with this new sheets name. I tried recording the macro and got this. (its portuguese but "TABELA DINÂMICA1" means "Dynamic Table1"; "CENTRO DE CUSTOS" means "Costs Centers").
Code:
ActiveSheet.PivotTables("Tabela dinâmica1").PivotFields("Centro de Custos"). _
CurrentPage = "(All)"
With ActiveSheet.PivotTables("Tabela dinâmica1").PivotFields("Centro de Custos" _
)
.PivotItems("300000").Visible = False
.PivotItems("301000").Visible = True 'here is where I am having a problem, I wish to change this to the variable name of the sheet "nomesheet" but I keep getting an error.
End With
Any ideas how I can change this? I will always be making the
.PivotItems("300000").Visible = False
.PivotItems("nomesheet").Visible = True (applying the new "filter" to the same cost center as the newly generated sheet.
I would expect the end code to look something like this ( I just don't know the correct way to code it):
Code:
Sub centrocustosheets()
Application.ScreenUpdating = False
Sheets(2).Select
Range("A3").Select
contar = Range(ActiveCell, ActiveCell.End(xlDown)).Count
ActiveCell.Offset(1, 0).Select
Do While ActiveCell <> Empty
nomesheet = ActiveCell.Text
Sheets("300000").Select
Sheets("300000").Copy After:=Sheets(7)
Sheets("300000 (2)").Select
Sheets("300000 (2)").Name = nomesheet
ActiveSheet.PivotTables("Tabela dinâmica1").PivotFields("Centro de Custos"). _
CurrentPage = "(All)"
With ActiveSheet.PivotTables("Tabela dinâmica1").PivotFields("Centro de Custos" _
)
.PivotItems("300000").Visible = False
.PivotItems("nomesheet").Visible = True
End With
ActiveSheet.PivotTables("Tabela dinâmica1").PivotFields("Centro de Custos"). _
CurrentPage = "(All)"
With ActiveSheet.PivotTables("Tabela dinâmica2").PivotFields("Centro de Custos" _
)
.PivotItems("300000").Visible = False
.PivotItems("nomesheet").Visible = True
End With
ActiveSheet.PivotTables("Tabela dinâmica1").PivotFields("Centro de Custos"). _
CurrentPage = "(All)"
With ActiveSheet.PivotTables("Tabela dinâmica3").PivotFields("Centro de Custos" _
)
.PivotItems("300000").Visible = False
.PivotItems("nomesheet").Visible = True
End With
Sheets(2).Select
ActiveCell.Offset(1, 0).Select
Loop
Application.ScreenUpdating = True
End Sub
Thank your for your attention and help.
Your sincerely,
final