vba pivot items
The UK's Number 1 for Microsoft Office Training Add this page to your favourites/bookmarksBookmark page
 
View printable version of pagePrintable version
Plus One Google
Customer: Sign in
Delegate: Sign in
Trainer: Log in

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » VBA Pivot Items

VBA Pivot Items

resolvedResolved · Low Priority · Version 2003

replyReply Thu 20 Jan 2011, 10:26Delegate Andy said...

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

For upcoming training course dates see: Pricing & availability

replyReply Wed 26 Jan 2011, 15:43Trainer Stephen said...

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, I'll take a look and attempt to resolve the issue

Regards

Stephen

 

Please browse our web site to find out more about
excel computer training and other Microsoft training courses.

Excel tip:

##### displaying in Excel

When you get a series of hash symbols (####) appearing in some of your cells in a spreadsheet, this can make you think that you've make some kind of mistake.

This is a common misconception - what this actually means is that the cell is not wide enough to fully display the content of the cell.

All you need to do to see what is actually in the cell is to widen the column that the cell is in.

View all Excel hints and tips


Microsoft Certified Partner Accredited Training Provider: Institute of IT Training Institute of Leadership and Management - Certified Courses Security Seal verified by visa, mastercard securecard