Results 1 to 4 of 4

Unable to add CubeField/PivotField as a Data Field in VBA

Threaded View

  1. #1
    Registered User
    Join Date
    03-04-2018
    Location
    New York, NY
    MS-Off Ver
    Office 2016
    Posts
    2

    Question Unable to add CubeField/PivotField as a Data Field in VBA

    I'm working on a very long Macro for my job and I am just about finished, but this is the last part and no matter what I do, I can't seem to figure out the fix. In this PivotTable, I need to have "Managers" as the columns and everything else (i.e. all of the months) in the Values section, with "Values" as the rows. After tinkering around, it seems as though all of the fields registered as CubeFields instead of PivotFields. When I run this, as soon as it gets to .Orientation = xlDataField, it throws a "Run-Time error 5...Invalid procedure call or argument." I also need to make sure that those DataFields are averaged and in a specific number format. Nothing I do works, and any guidance/fixes/workarounds would be greatly appreciated! Below are the macro and a download link to the file for tinkering.


    Sub addFieldsToPivot()
        Dim pvtTable As PivotTable
        Dim cubField As CubeField
        Dim i As Long
        Dim cubName As String
            
        Set pvtTable = ActiveSheet.PivotTables(1)
        For Each cubField In pvtTable.CubeFields
            For i = 1 To pvtTable.CubeFields.Count
                With pvtTable.CubeFields(i)
                    If .Name = "[effRent_perBed].[Manager]" Then
                        .Orientation = xlColumnField
                    Else:
                        .Orientation = xlDataField
                        'has to be averaged
                        'has to have number format of ##0.00
                    End If
                    
                End With
            Next
        Next
        
    End Sub
    Also posted this question on MrExcel, SuperUser/Stack Overflow and OzGrid
    Attached Files Attached Files
    Last edited by andrewstahl; 03-04-2018 at 03:54 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Unable to set the CurrebtPage property of the PivotField class
    By MattEd82 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-19-2016, 08:02 AM
  2. Pivottable Cubefield vs PivotField
    By rasonline in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-03-2014, 08:58 AM
  3. Unable to set orientation property of pivotfield class
    By williams485 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-22-2012, 12:51 PM
  4. Unable to set the currentpage property of the pivotfield class
    By adoepker in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-09-2011, 06:23 PM
  5. Unable to set the CurrentPage Property of the PivotField Class
    By Murali6688 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-18-2011, 12:16 PM
  6. Unable to set the CurrentPage Property of the PivotField Class
    By SDruley in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-09-2011, 01:39 PM
  7. Unable to get the PivotItems Property of the PivotField Class
    By vinay_bagare in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-09-2007, 05:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1