+ Reply to Thread
Results 1 to 8 of 8

Problem with defining arr for calculating Average and STDEV

  1. #1
    Valued Forum Contributor
    Join Date
    02-21-2010
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2007
    Posts
    502

    Problem with defining arr for calculating Average and STDEV

    I found an Excel VBA online that can calculate the average and the STDEV of numbers in Cells A1 to A10. See script below. This works. I tested it.
    What I would like to do now is change this script so that it can be used for 1D data arrays with varying amount of data.
    Assume I have data in column B. The first row is always row 2 but the last row varies.
    How would the script look like assuming that the size of the array is variable and the last row is variable?

    Please Login or Register  to view this content.

  2. #2
    Valued Forum Contributor
    Join Date
    02-21-2010
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2007
    Posts
    502

    Re: Problem with defining arr for calculating Average and STDEV

    I found two other functions for average and STDEV. These functions seem better suited for what I want to do.
    Question: How does the Sub "Compute" need to be modified so that I can used it for a 1D array with varying last row?

    Please Login or Register  to view this content.

  3. #3
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Problem with defining arr for calculating Average and STDEV

    You can use Excel builtin formulas for this, something like :

    Please Login or Register  to view this content.
    However if you want to use your existing UDF, the sub should be changed to something like this :
    Please Login or Register  to view this content.
    1. I care dog
    2. I am a loop maniac
    3. Forum rules link : Click here
    3.33. Don't forget to mark the thread as solved, this is important

  4. #4
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: Problem with defining arr for calculating Average and STDEV

    For use of formulea in arrays take a look at this.
    http://www.snb-vba.eu/VBA_Arrays_en.html#L_6.16
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  5. #5
    Valued Forum Contributor
    Join Date
    02-21-2010
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2007
    Posts
    502

    Re: Problem with defining arr for calculating Average and STDEV

    Dear karedog, thank you for the solutions. I personally like the Compute_Range solution the best. This one I will use. But I also got your Sub Compute() script to work. I will keep this one in mind.
    bakerman2, thanks for the link.

  6. #6
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Problem with defining arr for calculating Average and STDEV

    You are welcome, glad this can help you. Thanks for marking the thread as solved.


    Regards

  7. #7
    Valued Forum Contributor
    Join Date
    02-21-2010
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2007
    Posts
    502

    Re: Problem with defining arr for calculating Average and STDEV

    I wanted to add to your reputation but I was blocked from doing that. I have been given too many to you ...

  8. #8
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Problem with defining arr for calculating Average and STDEV

    Don't worry about that, thank you very much

+ 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] Problem with creating a correct formula for calculating STDEV for several time series.
    By Exceltrouble in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 03-14-2016, 09:43 AM
  2. [SOLVED] Problem calculating an average
    By mmccra2858 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-19-2013, 12:26 PM
  3. Problem Calculating an Average
    By Chrisb59 in forum Excel General
    Replies: 4
    Last Post: 08-01-2011, 05:41 AM
  4. Calculating stdev when values include #n/a
    By macaonghus in forum Excel General
    Replies: 2
    Last Post: 09-14-2009, 08:52 AM
  5. Calculating simple average and stdev
    By pani_hcu in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-11-2008, 11:29 AM
  6. average and stdev from groups of data
    By Charlie in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-09-2006, 12:00 AM
  7. STDEV without average
    By daniel in forum Excel General
    Replies: 5
    Last Post: 02-24-2005, 04:06 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