Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

vba pivot items

ResolvedVersion 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 courses

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
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

Excel tip:

Colouring cells containing formulas

Cells in a worksheet can contain values or they can contain formulas. You may wish to identify all the cells in your worksheet that contain formulas by colouring those cells.

Follow these steps:
1. Choose Edit > Go To menu, or press either F5 or Ctrl+G. Excel displays the Go To dialog box.
2. Click Special. Excel displays the Go To Special dialog box.
3. Select the Formulas radio button option.
4. Select OK.

At this point, every formula cell in the worksheet is selected, and those cells can be coloured formatted as desired.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.09 secs.