+ Reply to Thread
Results 1 to 6 of 6

Need a macro to create a special percentage calculation

  1. #1
    Registered User
    Join Date
    04-11-2012
    Location
    Nashville, TN
    MS-Off Ver
    Excel 2010
    Posts
    76

    Need a macro to create a special percentage calculation

    Hi all,
    Looking to use a macro to calculate Net Promoter Score. NPS is the percentage of Promoters minus the percentage of Detractors.
    Sample data attached.

    Promoter 20379
    Neutral 5816
    Detractor 2797

    The basic calculation:
    Calculate the percent of people who are promoters: 20379/28992 (70.3%)
    Calculate the percent of people who are detractors: 2797/28992 (9.6%)
    Subtract detractors % from promoters %: (70.3-9.6=60.7)

    Keeping all calculations to one decimal point.

    Still new to creating macros. I can create the equation in the cell, referring to the data in the three cells above it, but it'd be great if I could just have a macro assigned to a shortcut, which refers to data in the three cells immediately above where the result will wind up.

    Thanks so much for your help!
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Need a macro to create a special percentage calculation

    How's this:

    Please Login or Register  to view this content.
    P.S. Do you work in Market Research as well, then?

  3. #3
    Valued Forum Contributor AlvaroSiza's Avatar
    Join Date
    09-19-2007
    Location
    Staffordshire
    MS-Off Ver
    2007
    Posts
    591

    Re: Need a macro to create a special percentage calculation

    Slightly different than Andrew's above, the following creates a UDF that can be used anywhere in the workbook. To use, enter =NPS in a cell and select the promoters, neutral, and detractors (in that order) seperated by commas. In your example, it would look like =NPS(B1, B2, B3) and the result is 60.6%.

    Hope this helps.

    Please Login or Register  to view this content.
    Perhaps it was the Noid who should have avoided me...
    If you are satisfied with my solution click the small star icon on the left. Thanks
    1. Make a copy of your workbook and run the following code on your copy (just in case)
    2. With excel open, press ALT+F11 to open the Visual Basic Editor (VBE). From the "Insert" menu, select "Module".
    3. Paste the code from above into the empty white space. Close the VBE.
    4. From the developer tab, choose "Macros", select the Sub Name, and click "Run".

  4. #4
    Registered User
    Join Date
    04-11-2012
    Location
    Nashville, TN
    MS-Off Ver
    Excel 2010
    Posts
    76

    Re: Need a macro to create a special percentage calculation

    This is great, thanks Andrew-R! I do indeed work in market research, though (like vba) new to that as well!

  5. #5
    Registered User
    Join Date
    04-11-2012
    Location
    Nashville, TN
    MS-Off Ver
    Excel 2010
    Posts
    76

    Re: Need a macro to create a special percentage calculation

    AlvaroSiza, this is great, because the data isn't always arranged vertically for me. Thanks for your help!

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Need a macro to create a special percentage calculation

    It seems like a gratuitous use of a macro or UDF. How about just =(B1-B3)/SUM(B1:B3)
    Entia non sunt multiplicanda sine necessitate

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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