98.7% Of all customers recommend us, we're so confident about our results we publish all reviews and stats
View Live Stats View ReviewsForum home » Delegate support and help forum » Microsoft Excel VBA Training and help » VBA Pivot Items
VBA Pivot Items
Resolved · Low Priority · Version 2003
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
Training information:
Welcome. Please choose your application (eg. Excel) and then post your question. Our Microsoft Qualified trainers will then respond within 24 hours (working days). Frequently Asked Questions
Any suggestions, questions or comments? Please post in the Improve the forum thread. |
Excel tip:Keyboard Shortcuts to Add Rows or ColumnsCouple of other keyboard shortcuts. Shift+spacebar selects a row, Ctrl+spacebar selects a column. Select either row or column (or several) and use Ctrl and + to insert or Ctrl and - to delete rows or columns. |