+ Reply to Thread
Results 1 to 2 of 2

Calculation of coefficient of variation in Dynamic range with VBA

  1. #1
    Registered User
    Join Date
    02-06-2017
    Location
    Kathmandu
    MS-Off Ver
    2013
    Posts
    1

    Calculation of coefficient of variation in Dynamic range with VBA

    I have below data structure in excel.
    Name Order Date Purchage amount
    Ramesh 1/1/2017 465
    Ramesh 1/2/2017 6543
    Ramesh 1/3/2017 34
    Ramesh 1/4/2017 31
    Shankar 1/2/2017 89
    Shankar 1/3/2017 44
    Yuvraj 1/1/2017 545
    Yuvraj 1/1/2017 77
    Yuvraj 1/2/2017 851
    Yuvraj 1/3/2017 115
    Yuvraj 1/4/2017 67
    Yuvraj 1/5/2017 90
    Yuvraj 1/6/2017 920

    Based on above i want to create summary report as below with VBA.
    Name Count >=2/1/2017 And <= 5/1/2017 Purchase Sum >=2/1/2017 And <= 5/1/2017 CV for sum>=2/1/2017 And<= 5/1/2017
    Ramesh 3 6608 ??
    Shankar 2 133 ??
    Yuvraj 4 1123 ??


    Based on Name and date criteria, Sum and count can be handle easily with Countifs and sumifs inside VBA too but for CV(Coefficient of variation of purchase amount {C Column here} in above example ), I might have to define range dynamically and avoid zeros and calculate. But have no idea for defining dynamic range. Please help me. Actually i want to use dynamic range for the purpose because i can extend some some things with dynamic range.

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,957

    Re: Calculation of coefficient of variation in Dynamic range with VBA

    I almost didn’t respond to this since you did not attach a sample workbook. People usually will not take time to reconstruct a workbook, so it is usually best if you attach one.

    Fortunately, it was easy enough to copy and paste the text into a workbook and make a workbook out of it.

    Instructions on how to attach a workbook are at the bottom of this post.

    I made your data into an Excel table for two reasons: Excel tables know how big they are so if you add data to them or take data from them, formulas and pivot tables based on them will still reference the exact amount of data they need.

    Also Excel tables copy formulas down automatically.

    Cells J2 and K2 have the range that you want to calculate.

    I added some helper columns to the table.

    Column D determines if the date is within the range.

    Column E is the total for that person.

    Column F is the average.

    Column G is the standard deviation.

    Then I made a pivot table based on this data (Columns M to Q).

    The Amount is the Sum of the Amount Column
    The Average is the Average of the Amount Column
    The Standard Deviation is the Standard Deviation of the Amount Column

    All these are built-in functions of a Pivot table.

    Then I made a Calculated Formula in the pivot table of CV = Standard Deviation / Average.

    Technically speaking, this is the sum of the Standard Deviations / sum of the Averages. So for Ramesh, it is really dividing 8810 by 15035 instead of 2202 by 3759, but since there are an equal number of standard deviations and averages for a person, it doesn’t matter.

    To Attach a File:

    1. Scroll down to the window below your post Additional Options
    2. In the frame Attach Files you will see the button Manage Attachments
    3. Click the button.
    4. A new window will open titled Manage Attachments - Excel Forum.
    5. Click the Browse... button to locate your file for uploading.
    6. This will open a new window File Upload.
    7. Once you have located the file to upload click the Open button. This window will close.
    8. You are now back in the Manage Attachments - Excel Forum window.
    9. Click the Upload button and wait until the file has uploaded.
    10. Close the window and then click Submit.
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.
    Attached Files Attached Files
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

+ 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. calculation of variation of data of rolling columns
    By Dan3456 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-29-2016, 03:25 PM
  2. XIRR Variation adding a "Terminal Cashflow" to the Value Range
    By alonsogtz in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-05-2015, 11:08 AM
  3. Match ComboBox with dynamic range, then add Textbox1 to dynamic range
    By Lasse Moe in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-07-2014, 01:26 AM
  4. Increase the data variation range
    By jdbaba in forum Excel General
    Replies: 2
    Last Post: 11-04-2011, 01:18 PM
  5. Dynamic Drop Down List Variation
    By changpion in forum Excel General
    Replies: 5
    Last Post: 12-02-2010, 03:39 PM
  6. How to find range, coefficient of variation, interquartile range?
    By stathead in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 12-16-2007, 07:29 PM
  7. [SOLVED] formula for &amp;quot;coefficient of variation&amp;quot;
    By woodendummy in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-18-2005, 02:06 AM

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