N
Nav
Hello
Data is laid out in 5 columns, the first col should populate the row fields,
the second to populate the column fields and the next three should be the sum
data in the pivot table. However I am trying to get the data displayed if
the second column symbol = EUR, or USD. I have tried the recorder and made
some amendments, however this comes up with a “End if with Block If†compile
error, however I am not able to find where it has gone wrong. The code is
below, any ideas would be appreciated.
Sub Dr
Dim PivotItems As String
PivotItems =
ActiveSheet.PivotTables("PivotTable3").PivotFields("SYMBOL").PivotItems
Columns("A:E").Select
Range("E1").Activate
Columns("A:E").EntireColumn.AutoFit
Range("B3").Select
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"Sheet1!A:E").CreatePivotTable TableDestination:="", TableName:= _
"Dremel", DefaultVersion:=xlPivotTableVersion10
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
ActiveSheet.PivotTables("Dremel").AddFields RowFields:=Array("CLIENT_ID" _
, "Data"), ColumnFields:="SYMBOL"
With ActiveSheet.PivotTables("Dremel").PivotFields("ASSET_PCENT")
.Orientation = xlDataField
.Position = 1
.Function = xlSum
End With
With ActiveSheet.PivotTables("Dremel").PivotFields("MARKET_VALUE")
.Orientation = xlDataField
.Position = 2
.Function = xlSum
End With
With ActiveSheet.PivotTables("Dremel").PivotFields("MARKET_VALUE_LOCAL")
.Orientation = xlDataField
.Position = 3
.Function = xlSum
ActiveWorkbook.ShowPivotTableFieldList = True
With ActiveSheet.PivotTables("Dremel").PivotFields("SYMBOL")
If PivotItems = "GBP" Then
ActiveSheet.PivotTables("Dremel").PivotFields("SYMBOL").PivotItems.Visible =
True Else
If PivotItems = "eur" Then
ActiveSheet.PivotTables("Dremel").PivotFields("SYMBOL").PivotItems.Visible =
True Else
If PivotItems = "usd" Then
ActiveSheet.PivotTables("Dremel").PivotFields("SYMBOL").PivotItems.Visible =
True Else
ActiveSheet.PivotTables("Dremel").PivotFields("SYMBOL").PivotItems.Visible =
False
End If
` error occurs here
End With
ActiveSheet.PivotTables("Dremel").Activate
Range("A4").Select
ActiveSheet.PivotTables("Dremel").PivotFields("CLIENT_ID").AutoSort _
xlAscending, "Sum of ASSET_PCENT"
End Sub
Thank you in advance for your help.
Nav
Data is laid out in 5 columns, the first col should populate the row fields,
the second to populate the column fields and the next three should be the sum
data in the pivot table. However I am trying to get the data displayed if
the second column symbol = EUR, or USD. I have tried the recorder and made
some amendments, however this comes up with a “End if with Block If†compile
error, however I am not able to find where it has gone wrong. The code is
below, any ideas would be appreciated.
Sub Dr
Dim PivotItems As String
PivotItems =
ActiveSheet.PivotTables("PivotTable3").PivotFields("SYMBOL").PivotItems
Columns("A:E").Select
Range("E1").Activate
Columns("A:E").EntireColumn.AutoFit
Range("B3").Select
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"Sheet1!A:E").CreatePivotTable TableDestination:="", TableName:= _
"Dremel", DefaultVersion:=xlPivotTableVersion10
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
ActiveSheet.PivotTables("Dremel").AddFields RowFields:=Array("CLIENT_ID" _
, "Data"), ColumnFields:="SYMBOL"
With ActiveSheet.PivotTables("Dremel").PivotFields("ASSET_PCENT")
.Orientation = xlDataField
.Position = 1
.Function = xlSum
End With
With ActiveSheet.PivotTables("Dremel").PivotFields("MARKET_VALUE")
.Orientation = xlDataField
.Position = 2
.Function = xlSum
End With
With ActiveSheet.PivotTables("Dremel").PivotFields("MARKET_VALUE_LOCAL")
.Orientation = xlDataField
.Position = 3
.Function = xlSum
ActiveWorkbook.ShowPivotTableFieldList = True
With ActiveSheet.PivotTables("Dremel").PivotFields("SYMBOL")
If PivotItems = "GBP" Then
ActiveSheet.PivotTables("Dremel").PivotFields("SYMBOL").PivotItems.Visible =
True Else
If PivotItems = "eur" Then
ActiveSheet.PivotTables("Dremel").PivotFields("SYMBOL").PivotItems.Visible =
True Else
If PivotItems = "usd" Then
ActiveSheet.PivotTables("Dremel").PivotFields("SYMBOL").PivotItems.Visible =
True Else
ActiveSheet.PivotTables("Dremel").PivotFields("SYMBOL").PivotItems.Visible =
False
End If
` error occurs here
End With
ActiveSheet.PivotTables("Dremel").Activate
Range("A4").Select
ActiveSheet.PivotTables("Dremel").PivotFields("CLIENT_ID").AutoSort _
xlAscending, "Sum of ASSET_PCENT"
End Sub
Thank you in advance for your help.
Nav