Gideon1995
New Member
- Joined
- May 8, 2018
- Messages
- 3
I am using code to generate code. The generated code is stored within a string, but i can't execute the string. I have been searching for hours but still find nothing. The goal is to update the filters within a pivot table to only show certain months between a start and finishing date, without having to go and select them.
Code:
Dim field As String
field = "ActiveSheet.PivotTables(" & """FinanceTable""" & ").PivotFields( _" & Chr(13) & """[Transaction Date].[Date YQMD].[Month]""" & ").VisibleItemsList = Array( _" & Chr(13)
Range("F1").Value = field
'Add necessary month fields
For i = Starting_Month To Current_Month
If i < 10 Then
field = field + """[Transaction Date].[Date YQMD].[Month].&[20180" & i & "]""" & ", _" & Chr(13)
Range("F1").Value = field
Else
field = field + "[Transaction Date].[Date YQMD].[Month].&[2018" & i & "]"""
End If
Next i
field = field & "ActiveSheet.PivotTables(" & "FinanceTable" & ").PivotFields( _" & Chr(13) & """[Transaction Date].[Date YQMD].[Day]""" & ").VisibleItemsList = Array("""")"
Range("F1").Value = field
*Execute String as Function Code*
Last edited by a moderator: