+ Reply to Thread
Results 1 to 12 of 12

Need to change PivotField Name based on a Cell

  1. #1
    Registered User
    Join Date
    07-26-2016
    Location
    Singapore
    MS-Off Ver
    2013
    Posts
    18

    Need to change PivotField Name based on a Cell

    Hi Guys,

    I have a problem with creating a code for Pivot Table. The problem is that I wish to add a Pivot Field to Data, but this field has to depend on what is within a particular cell of the workbook. For example, if the cell contains the text "January", then the PivotField to be added to the Data in the Pivot Table is to be "January". I have the following code which is giving me an error.

    Please Login or Register  to view this content.
    Much appreciated for your advice, thank you.

  2. #2
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Need to change PivotField Name based on a Cell

    Hello
    Try remove Set from this line
    Please Login or Register  to view this content.
    Just use
    Please Login or Register  to view this content.
    as this variable would be string "str" not object
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  3. #3
    Registered User
    Join Date
    07-26-2016
    Location
    Singapore
    MS-Off Ver
    2013
    Posts
    18

    Re: Need to change PivotField Name based on a Cell

    Hi, that still doesn't solve the problem. In fact, the PivotField does not recognize str as a valid field name.

  4. #4
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Need to change PivotField Name based on a Cell

    What's the error message that appears to you?
    And what's the value of the variable "str"?

  5. #5
    Registered User
    Join Date
    07-26-2016
    Location
    Singapore
    MS-Off Ver
    2013
    Posts
    18

    Re: Need to change PivotField Name based on a Cell

    Hi, so I just removed str and typed directly into the pivot field such that my code looks like this:

    Please Login or Register  to view this content.
    Error message is: Unable to get PivotFields property of the PivotTable Class.
    May-17 is an actual field that I can drag manually to the values section. I don't understadn why this doesn't work in my vba

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Need to change PivotField Name based on a Cell

    Is the value actually 'May-17' or is it a date that's been formatted to display 'May-17'?
    If posting code please use code tags, see here.

  7. #7
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Need to change PivotField Name based on a Cell

    May be adding Cstr before the variable str would solve the problem

  8. #8
    Registered User
    Join Date
    07-26-2016
    Location
    Singapore
    MS-Off Ver
    2013
    Posts
    18

    Re: Need to change PivotField Name based on a Cell

    Ok I guess I'll have to share the file because it's a bit hard to explain.

    In the "Cover Tab", the user gets to select which Month and Year and I would like that particular selection to be added to the Data Field in the Pivot Table. Thank you so much for your help

    I'm having trouble uploading the file here, can you download it from this link?

    https://drive.google.com/open?id=0B0...VItcnpwSEdhSWc

  9. #9
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,830

    Re: Need to change PivotField Name based on a Cell

    Will you please attach a sample Excel workbook here? Many members will not access file-sharing sites.

    Unfortunately the attachment icon doesn't work at the moment, so to attach an Excel file you have to do the following: just before posting, scroll down to Go Advanced and then scroll down to Manage Attachments. Now follow the instructions at the top of that screen.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  10. #10
    Registered User
    Join Date
    07-26-2016
    Location
    Singapore
    MS-Off Ver
    2013
    Posts
    18

    Re: Need to change PivotField Name based on a Cell

    I'm afraid Manage Attachments is not working for me either. It's ok, I will solve it myself if no one wants to download the file.

  11. #11
    Registered User
    Join Date
    07-26-2016
    Location
    Singapore
    MS-Off Ver
    2013
    Posts
    18

    Re: Need to change PivotField Name based on a Cell

    Hi the file as attached for your reference.
    Attached Files Attached Files

  12. #12
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,830

    Re: Need to change PivotField Name based on a Cell

    Rule 08: Cross-posting Without Links

    Your post does not comply with Rule 8 of our Forum RULES. Do not cross-post your question on multiple forums without including links here to the other threads on other forums.

    Cross-posting is when you post the same question in other forums on the web. The last thing you want to do is waste people's time working on an issue you have already resolved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser) to the cross-post.

    Expect cross-posted questions without a link to be closed and a message will be posted by the moderator explaining why. We are here to help so help us to help you!

    Read this to understand why we ask you to do this, and then please edit your first post to include links to any and all cross-posts in any other forums (not just this site).

    No further help to be offered, please, until the OP has complied with this request.

+ 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. [SOLVED] EXCEL NEWB.....Change cell color based on text in a cell on another sheet
    By anon1988 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-27-2014, 12:16 AM
  2. Change the content of a cell based on change the current date
    By aimanraya in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-14-2014, 07:07 AM
  3. [SOLVED] OptionButton choice to populate ListBox based on the "Region" found in a PivotField.
    By EnigmaMatter in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 02-26-2014, 04:30 PM
  4. pivotfield properties for vba, eliminating rows based on subtotal
    By osubuckeye2007 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-02-2013, 03:32 PM
  5. Replies: 3
    Last Post: 12-16-2012, 12:49 PM
  6. Change cell values based on Active Cell Address in Excel 2007 with no VBA
    By bdmistri in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-07-2009, 02:01 PM
  7. [SOLVED] Macro to change the PivotField to sum
    By Vick in forum Excel General
    Replies: 3
    Last Post: 12-21-2005, 06:40 PM

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