+ Reply to Thread
Results 1 to 11 of 11

Add/Remove Multiple Calculated Fields with Listbox (ISSUE)

  1. #1
    Registered User
    Join Date
    10-17-2012
    Location
    Texas
    MS-Off Ver
    Excel 2007
    Posts
    71

    Add/Remove Multiple Calculated Fields with Listbox (ISSUE)

    I'm reluctant that someone will be able to figure this out, but here it goes:

    When clicking my listbox items (MultiSelect LisbBox), it populates various calcuated fields in my pivot table. I'm trying to figure out how to Remove and Add my calculated field items when they are selected in the listbox. The code below runs without errors, and it populates the pivot field with the desired calculated fields. However, when I DESELECT the 2nd listbox item, it does not remove the calculated field. If I deselect the 1st listbox item, then ALL of the calculated fields will be removed from the pivottable. How do I modify the code below so that each calculated field is removed individually when it is deselected from the listbox.

    Many thanks in advance if someone can solve this!

    Please Login or Register  to view this content.
    It looks like different things happen when I move around the position of this line of code:
    Please Login or Register  to view this content.
    but I'm not sure if this is the issue.
    Last edited by Platinum3x; 12-05-2014 at 02:16 PM.

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

    Re: Add/Remove Multiple Calculated Fields with Listbox (ISSUE)

    How is anybody able to test the code?

  3. #3
    Registered User
    Join Date
    10-17-2012
    Location
    Texas
    MS-Off Ver
    Excel 2007
    Posts
    71

    Re: Add/Remove Multiple Calculated Fields with Listbox (ISSUE)

    Sorry about that! I have attached a sample sheet below. ListBox 8 on the Accounts Pivot Tab has the code for the calculated fields as described above. I also just realized that the listboxes in my sheet scale very differently on a different computer screen (home vs work). Is there any way to ensure the scale stays the same and doesn't get screwed up? Thanks!

    ListBox Issues Example.xlsm

  4. #4
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Add/Remove Multiple Calculated Fields with Listbox (ISSUE)

    I'm a little confused. Your calculated field names don't match the items in the listbox, so how should the code determine which fields should be visible?
    Remember what the dormouse said
    Feed your head

  5. #5
    Registered User
    Join Date
    10-17-2012
    Location
    Texas
    MS-Off Ver
    Excel 2007
    Posts
    71

    Re: Add/Remove Multiple Calculated Fields with Listbox (ISSUE)

    Hey Romper,

    The calculated field names are determined on sheet SCodes in Range AE3:AE15. This is needed so the macro can function dynamically as different months of data are run. The correct calculated field is added/removed by the listbox selection (dictated by the listindex). For example, .Selected(0) = T1CHG$ 12 and STANDCHG$ 12, .Selected(1) = T1CHG 11 and STANDCHG$ 11, Etc. Hope that makes sense.

  6. #6
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Add/Remove Multiple Calculated Fields with Listbox (ISSUE)

    Not really. None of those items match the names of your actual calculated fields - they're just the captions that you give them when you add them to the table it appears.

  7. #7
    Registered User
    Join Date
    10-17-2012
    Location
    Texas
    MS-Off Ver
    Excel 2007
    Posts
    71

    Re: Add/Remove Multiple Calculated Fields with Listbox (ISSUE)

    This method is working fine for the fields that are not calculated. This issue pertains to removal and addition of calculated fields, which is a "feature" that has caused similar problems for many others. I will try to keep hammering on the solution.

  8. #8
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Add/Remove Multiple Calculated Fields with Listbox (ISSUE)

    I think you're missing my point. There is nothing in your code that can add other calculated fields because the names of the calculated fields (unlike the regular fields) are not the same as the items in your list. It is quite possible to show and hide calculated fields.

  9. #9
    Registered User
    Join Date
    10-17-2012
    Location
    Texas
    MS-Off Ver
    Excel 2007
    Posts
    71

    Re: Add/Remove Multiple Calculated Fields with Listbox (ISSUE)

    Ah okay I see what you're saying now, thanks for clarifying! So, is it possible to have two calculated fields added to my pivot table with one selection of my listbox? I select a listbox item and I want both STANDCHG$ and T1CHG$ to populate. I'm not sure what the name of my listbox items should be to accomplish this, if that is the issue that's holding this back.

    Thanks!

  10. #10
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Add/Remove Multiple Calculated Fields with Listbox (ISSUE)

    Try this:
    Please Login or Register  to view this content.
    I've assumed that the calculated field names are in reverse order to the listbox - i.e. the first item in the list relates to "STANDCHG$ 12" and the last to "STANDCHG$ 1" (and similarly with T1CHG$)

  11. #11
    Registered User
    Join Date
    10-17-2012
    Location
    Texas
    MS-Off Ver
    Excel 2007
    Posts
    71

    Re: Add/Remove Multiple Calculated Fields with Listbox (ISSUE)

    That works perfectly!!! Thanks so much for your help again, Romper

+ 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. Issue with Calculated Fields with pivot tables
    By msantucci in forum Excel Charting & Pivots
    Replies: 5
    Last Post: 09-18-2014, 10:31 AM
  2. [SOLVED] Populate Multiple Fields from Mutiple Column Listbox
    By sgwilliams in forum Excel General
    Replies: 6
    Last Post: 02-07-2011, 02:47 PM
  3. Calculated Fields Based on Running Total Fields?
    By Kruncher in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-12-2006, 01:25 PM
  4. Replies: 3
    Last Post: 05-11-2006, 01:55 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