Andy has attended:
No courses
VBA Pivot Items
Hi there
I have set up a macro to produce a pivot table based on a set of finance data.
In the column field I have month and in the field the values will be
Mth 1
Mth 2
...
Mth 12
I have set up code for an input box to ask for the month to be shown as below
Public Sub MyInputBox()
Dim MyInput As String
MyInput = InputBox("This is my InputBox", _
"MyInputTitle", "Enter your input text HERE")
If MyInput = "Enter your input text HERE" Or _
MyInput = "" Then
Exit Sub
End If
MsgBox "The text from MyInputBox is " & MyInput
End Sub
Then in the macro to create the pivot table I have the following code to hide the other months
With ActiveSheet.PivotTables("FinanceData").PivotFields("Month")
For i = 1 To .PivotItems.Count
If .PivotItems(i).Name = MyInput Then
.PivotItems(i).Visible = True
Else: .PivotItems(i).Visible = False
End If
Next i
End With
When this runs I get run-time error 1004 Unable to set the visible property of the pivotitem class.
I am not sure if the issue is because MyInput value is not carried across to the second macro or for another reason(when I step into the code and hover over MyInput I get MyInput = empty in the pivottable macro).
I don't want the My input code within the macro for the pivot table as this needs to be repeated for 4 seperate pivot tables and ideally I only want 1 input
Any help would be much appreciated
Andy
RE: VBA Pivot Items
Hi Andy
Thanks for your question
This one is difficult to comment on without seeing the workbook with the code. If you could email a copy of it to me at sw@stl-training.co.uk, I'll take a look and attempt to resolve the issue
Regards
Stephen