+ Reply to Thread
Results 1 to 5 of 5

VBA or Excel code to calculate the % of a unique value and how often it occurs

  1. #1
    Registered User
    Join Date
    06-09-2015
    Location
    England
    MS-Off Ver
    2010
    Posts
    8

    VBA or Excel code to calculate the % of a unique value and how often it occurs

    Hi All,

    Please would you be able to assist me. Im a bit of an excel noob still but im trying to do a sports stock list for a local team i help manage and i would like to setup some VBA code or a formula.

    What im trying to achieve is the following,

    - Look through column "D" (ItemID) and sort into unique references
    - Then count the total quantity using column "G" (Quantity) for each unique reference from column "D" (ItemID)
    - Now using the above, make a new column which shows the percentage of the quantity against the total quantity for each unique reference.


    TeamCode TeamName TeamArea ItemID Description Group Quantity Percentage of stock
    A12345 Team1 SE 0123 Footballs SE1 5 25%
    A12346 Team2 SE 0123 Footballs SE1 5 25%
    A12346 Team3 SE 0123 Footballs SE1 10 50%
    A12348 Team5 SE 0234 Tennis Balls SE1 2 50%
    A12359 Team8 SE 0234 Tennis Balls SE1 2 50%
    A12368 Team12 SE 586 Cricket Bats SE1 10 25%
    A12438 Team15 SE 586 Cricket Bats SE1 30 75%
    A15677 Team23 SE 9874 Golf Clubs SE1 90 100%
    A12178 Team25 SE 98654 Basketballs SE1 23 100%


    So as you can see above. Column "H" (Percentage of stock) shows the percentages of the quantity (Column "G") against the total quantity in reference to the unique reference in column "D" (ItemID).

    Ive probably over complicated my explanation as well, so i hope it all makes sense and i appreciate your help.

    Thank you.

    Kind Regards
    Z
    Last edited by zainycmt; 06-14-2016 at 05:31 AM. Reason: Solved

  2. #2
    Forum Expert Crooza's Avatar
    Join Date
    10-19-2013
    Location
    Hunter Valley, Australia
    MS-Off Ver
    Excel 2003 /7/10
    Posts
    2,082

    Re: VBA or Excel code to calculate the % of a unique value and how often it occurs

    Put this in H2 (assuming the header row is row 1) and drag down

    =G2/SUMIF($D$2:$D$10,D2,$G$2:$G$10)
    Happy with my advice? Click on the * reputation button below

  3. #3
    Registered User
    Join Date
    06-09-2015
    Location
    England
    MS-Off Ver
    2010
    Posts
    8

    Re: VBA or Excel code to calculate the % of a unique value and how often it occurs

    Brilliant, ty Crooza. Worked a charm.

    Only one issue i have is i have about 1000 lines and when i change the range to D:D and G:G. It takes a while to drag down. Is there a quick way to put the code in for each cell? I did try the "fill down" option but it crashed the document multiple times.

    Thank you again.

  4. #4
    Forum Expert Crooza's Avatar
    Join Date
    10-19-2013
    Location
    Hunter Valley, Australia
    MS-Off Ver
    Excel 2003 /7/10
    Posts
    2,082

    Re: VBA or Excel code to calculate the % of a unique value and how often it occurs

    Rather than drag the outline for the D and G range down manually edit the first formula to D2:D1000 and the same for the G range then double click the formula to auto fill

  5. #5
    Registered User
    Join Date
    06-09-2015
    Location
    England
    MS-Off Ver
    2010
    Posts
    8

    Re: VBA or Excel code to calculate the % of a unique value and how often it occurs

    Perfect. Thank you again, life saver!

    Superstar!!!

    Kind Regards
    Z

+ 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] help for calculate times of occurs start from 0 with name & date
    By breadwinner in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-03-2013, 10:31 AM
  2. [SOLVED] Reposition data on sheet and calculate how many times it occurs
    By djfscouse in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-17-2013, 05:45 PM
  3. Replies: 2
    Last Post: 02-07-2013, 03:16 AM
  4. [SOLVED] How to calculate a formula when an error occurs within the related cells
    By cassyleighnz in forum Excel General
    Replies: 5
    Last Post: 12-11-2012, 05:00 AM
  5. [SOLVED] Counting Number of times a Unique value occurs in an Array
    By Foreverlearning in forum Excel Programming / VBA / Macros
    Replies: 44
    Last Post: 07-12-2012, 08:18 PM
  6. How do I calculate times each word occurs in a column of cells?
    By MTSusce in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-18-2006, 08:35 PM
  7. execute code in one worksheet when change occurs in another
    By suzetter in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-16-2005, 02:05 PM

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