+ Reply to Thread
Results 1 to 12 of 12

Need help!! Create percentage inside each class

  1. #1
    Registered User
    Join Date
    02-28-2014
    Location
    ITALY
    MS-Off Ver
    Excel 2007
    Posts
    8

    Need help!! Create percentage inside each class

    Hi everybody!
    I m writing from Italy and I am not able to go out from a vba problEM
    As you can see in the attached file, I have a column of classes , a columns of related revenues and the total for eache class.
    I have to create a column, next to these, where I can create the percentage with respect the sum of each class (as you can see by the formula).
    My problem is I am not able to say vba to find the totals and to create the percentage just with the revenues related to that total.
    Thanks in advance for the help, I really need them.
    I cannot understand how to create this.
    Thank everybody!!
    Max
    p.s: I have to work on excel2010
    Attached Files Attached Files

  2. #2
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Need help!! Create percentage inside each class

    Hi Massimo,

    This is a little long and there are probably better ways, but this might work? If I nderstand correctly you need a NEW column with percentage within Class B, or Class C, etc? So first line (Class D) needs to show percent of the sum of ALL CLASS D?

    if so, try the code below:

    Please Login or Register  to view this content.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  3. #3
    Registered User
    Join Date
    02-28-2014
    Location
    ITALY
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Need help!! Create percentage inside each class

    Hi Arkadi!!
    First of all, thank you for the reply!!
    I try to explain better cause in my previus post I have been not so clear
    tha table represents output of pivot.
    The column B are some classes (the percentage in the name of the classes maybe are ambigous, just call them class A,B,C,D,E,F,G,H). For each class, IF there are elements in the database of the pivot, there are the sum of the revenues.
    So, for example, for a product X, there are maybe class, A,C,F,H and the related revenues. at the end of product X there is the sum.
    for another product, let s say Y, there are just A,G,H classes with the related revenues and sums.
    And so on.
    With another extraction from pivot, I could have product with all the classes, or just 3, or 4, ..... . That 's the problem. Every products could have different number of classes (and so rows).
    What I need is a column, after the revenues, where there aren't the absolute values of the revenues, but the percentage with respect to the specific sum.
    I need to say to vba to find each sum related to the product and create the percentage.
    I tried the code you kindly wrote but it doesnt create the right percentage.
    Now I am trying to find a solution (but not sure no be able).
    I attached a better version of excel file.
    Thanks!!!!
    Attached Files Attached Files

  4. #4
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Need help!! Create percentage inside each class

    MassimoT,

    Sorry, I guess I misunderstood your requirements. I'll take a look at this again and get back to you.

    Question: Will the format always be the same? I mean will the line for the Total of each product be blank in column B? Also, do the totals come from your pivot table extraction, or does the code need to calculate that?
    Right now I am assuming yes, B blank, and that the total is part of your data and the macro does not need to calculate that?
    Last edited by Arkadi; 03-25-2014 at 10:15 AM.

  5. #5
    Registered User
    Join Date
    02-28-2014
    Location
    ITALY
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Need help!! Create percentage inside each class

    Hi Arkadi!!
    Yes you are right!!
    the cell next to total in column B si always blank.And pivot already gives me that total.
    I just have to create two colomuns next to pivot with the percentages of the "weight" of each class, with respctc to the total of each category.
    But the pivot extractions can vary a lot. Sometimes a category with all the classes can be followed by another with just one class (and so the class and the total have the same value. ), and then another with 3 classes and so on. Thanks for your help.
    Massimo

  6. #6
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Need help!! Create percentage inside each class

    MassimoT,

    Sorry I didn't get to help yesterday, do you need 100% to show up next to the totals also? The code below does the % for the revenues, leaving the total line blank for % since that is always 100%, but if you need it we can modify the code.... let me know if this works for you...
    One thing... this code gives you results with 2 decimals and the % symbol, so remove cell formatting of column E from your sheet?

    Please Login or Register  to view this content.

  7. #7
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Need help!! Create percentage inside each class

    MassimoT,

    Sorry I didn't get to help yesterday, do you need 100% to show up next to the totals also? The code below does the % for the revenues, leaving the total line blank for % since that is always 100%, but if you need it we can modify the code.... let me know if this works for you...
    One thing... this code gives you results with 2 decimals and the % symbol, so remove cell formatting of column E from your sheet?

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    02-28-2014
    Location
    ITALY
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Need help!! Create percentage inside each class

    Hi Arkadi!!!
    This code works so well!!! I understand how my knowledge in vba is full of gaps!!
    When the interval are fixed I can write right codes , but , as in this case when they vary, I am unprepared.
    The last thing. In the percentage columns create by the code, the cells corresponding to the total are blank. Obviusly that cells always are 100%.
    Would it be possible to calculate even this cell, in order to make appears the value 100% ?
    I'm trying to modify your code to do this, but unsuccefully...
    Still thanks for this great help
    Massimo

  9. #9
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Need help!! Create percentage inside each class

    hi massimo, try this instead then,

    Please Login or Register  to view this content.
    Last edited by Arkadi; 03-27-2014 at 09:14 AM.

  10. #10
    Registered User
    Join Date
    02-28-2014
    Location
    ITALY
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Need help!! Create percentage inside each class

    It works perfectly!!!
    Thanks a lot!!!!!
    Massimo

  11. #11
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Need help!! Create percentage inside each class

    You are welcome Glad it worked out for you. Please remember to mark the thread as solved, rep appreciated too, but not required

  12. #12
    Registered User
    Join Date
    02-28-2014
    Location
    ITALY
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Need help!! Create percentage inside each class

    Done both!!!
    Last edited by MassimoT; 03-28-2014 at 02:25 PM.

+ 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. Create Class Analysis
    By The Learner in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-04-2013, 02:12 AM
  2. Create Object (Class)
    By lampis in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 02-22-2012, 11:57 AM
  3. VSTO Create a New Class
    By goss in forum Word Programming / VBA / Macros
    Replies: 1
    Last Post: 08-08-2010, 07:29 PM
  4. Access property of an Object inside class 2
    By bettatronic in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-01-2007, 03:55 AM
  5. [SOLVED] Create an array inside a For...Next loop
    By Eric Winegarner in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-26-2005, 08:05 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