+ Reply to Thread
Results 1 to 2 of 2

VBA to calculate Standard Deviation

Hybrid View

  1. #1
    Registered User
    Join Date
    10-28-2014
    Location
    Long Beach, California
    MS-Off Ver
    2007
    Posts
    10

    VBA to calculate Standard Deviation

    Hello,

    I'm trying to build a macro (that I will assign to a command button) that will calculate the standard deviation of a range of values. The issue I'm running into is that the number of values to be included in the formula may change, and I don't want to have to go back and edit the code to incorporate all values. Long story short: I have the below code which calculates the standard deviation of the values from C3 to C106. How do I change it so that it will take all the values in column C...if there are more than through C106? Thank you!!

    Sub StdDev()
    '
    ' StdDev Macro
    '
    
    '
        Range("E8").Formula = "=STDEV(C3:C106)"
        Range("E8").Select
        Selection.Style = "Percent"
        Selection.NumberFormat = "0.0%"
        Selection.NumberFormat = "0.00%"
    End Sub

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,982

    Re: VBA to calculate Standard Deviation

    Assuming there is nothing else in column C below the data:
    Sub StdDev()
    '
    ' StdDev Macro
    '
    
    '
        Dim LastRow As Long
        LastRow = ActiveSheet.Cells(Rows.Count, "C").End(xlUp).Row
        With Range("E8")
            .Formula = "=STDEV(C3:C" & LastRow & ")"
            .NumberFormat = "0.00%"
        End With
    End Sub
    Everyone who confuses correlation and causation ends up dead.

+ 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. How to calculate standard deviation of a product?
    By Serina90 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-01-2013, 10:26 AM
  2. Calculate Standard Deviation
    By goss in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-05-2013, 05:11 AM
  3. Need a more efficient way to calculate Standard Deviation
    By StevenAlberta in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 07-24-2012, 03:17 PM
  4. Calculate one standard deviation from mean
    By missyreiber in forum Excel General
    Replies: 3
    Last Post: 09-08-2010, 11:40 AM
  5. [SOLVED] How to calculate 2 standard deviation?
    By Li in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-12-2005, 05:06 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