+ Reply to Thread
Results 1 to 2 of 2

Error 438 on Pivot calculated field creation using string variables

  1. #1
    Registered User
    Join Date
    11-26-2013
    Location
    France
    MS-Off Ver
    Excel 2007
    Posts
    1

    Error 438 on Pivot calculated field creation using string variables

    Hello,

    I am trying to drive the creation of a large number of fields without hardcoding everything.
    .CalcuatedFields.Add works ok when Const strings are used but fails (438) when variables are used.



    Sub TEST()

    Dim pt As PivotTable

    Dim pf As PivotField

    Dim calcfld_1_src As String
    Dim calcfld_1_formula As String
    Dim calcfld_1_name As String

    calcfld_1_src = "JAN APPR"
    calcfld_1_formula = "= Jan Billable Hours + Jan Cost Recovery Hours "


    Sheets("Pivot").Activate
    Set pt = ActiveSheet.PivotTables(1)


    With pt

    For Each pf In pt.CalculatedFields

    pf.Delete

    Next pf

    .CalcuatedFields.Add calcfld_1_src, calcfld_1_formula

    ' ......................



    When calcfld_1_src, calcfld_1_formula are defined as constants :
    Const calcfld_1_src As String = "JAN APPR"


    the calculated field is created.

    Is the there a way around this?

    Best regards
    Stephen

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,480

    Re: Error 438 on Pivot calculated field creation using string variables

    Add code tags to your post, Click the Edit Post icon and follow instructions.

    CodeTags.jpg

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Pivot Table Calculated Field Math Error
    By jcranst in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 07-30-2013, 04:28 PM
  2. Replies: 0
    Last Post: 06-26-2012, 09:06 PM
  3. Pivot Table Calculated Field Formula Error
    By aharb in forum Excel General
    Replies: 0
    Last Post: 04-04-2012, 11:48 AM
  4. Use of variables in pivot calculated field
    By wemmenh in forum Excel General
    Replies: 0
    Last Post: 06-07-2009, 11:28 PM
  5. [SOLVED] pivot table formulas for calculated field or calculated item
    By Vicky in forum Excel General
    Replies: 3
    Last Post: 06-06-2006, 12:10 AM

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