Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6879235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:49:15+00:00 2026-05-27T04:49:15+00:00

Below I am trying to write a script the goal of which is to

  • 0

Below I am trying to write a script the goal of which is to calculate some summary statistics for a few different columns of numbers. I have gotten some help on it up to the “Need help below” mark. But beyond that I am flabergasted as to how to calculate the simple stats (sum, mean, standard deviation, coefficient of variation). I know VB has scripts for these stats, which I have included in my code, but I guess I need to do some extra declaring or something. Advice much appreciated. Thanks.

    Sub TOAinput()

    Const n As Integer = 648

    Dim stratum(n), hybrid(n), acres(n), hhsz(n), offinc(n)
    Dim s1 As Integer
    Dim s2 As Integer
    Dim i As Integer

    For i = 1 To n
    stratum(i) = Worksheets("hhid level").Cells(i + 1, 2).Value
    Next i

    s1 = 0
    s2 = 0
    For i = 1 To n
        If stratum(i) = 1 Then
        s1 = s1 + 1
        Else:
        s2 = s2 + 1
        End If
    Next i

    Dim acres1(), hhsz1(), offinc1(), acres2(), hhsz2(), offinc2()
    ReDim acres1(s1), hhsz1(s1), offinc1(s1), acres2(s2), hhsz2(s2), offinc2(s2)

    'data infiles: acres, hh size, off-farm income,

    For i = 1 To n
    acres(i) = Worksheets("hhid level").Cells(i + 1, 4).Value
    hhsz(i) = Worksheets("hhid level").Cells(i + 1, 5).Value
    offinc(i) = Worksheets("hhid level").Cells(i + 1, 6).Value
    Next i

    s1 = 0
    s2 = 0
    For i = 1 To n
        If stratum(i) = 1 Then
        s1 = s1 + 1
        acres1(s1) = acres(i)
        hhsz1(s1) = hhsz(i)
        offinc1(s1) = offinc(i)
        Else:
        s2 = s2 + 1
        acres2(s2) = acres(i)
        hhsz2(s2) = hhsz(i)
        offinc2(s2) = offinc(i)
        End If
    Next i

    '****************************
    'Need help below
    '****************************

    Dim sumac1, sumac2, mhhsz1, mhhsz2, cvhhsz1, cvhhsz2

    sumac1 = Sum(acres1)
    sumac2 = Sum(acres2)
    mhhsz1 = Average(hhsz1)
    mhhsz2 = Average(hhsz2)
    cvhhsz1 = StDev(hhsz1) / Average(hhsz1)
    cvhhsz2 = StDev(hhsz2) / Average(hhsz2)


    End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:49:16+00:00Added an answer on May 27, 2026 at 4:49 am

    Sum, Average and StdDev are worksheet functions and cannot be used directly in VBA.

    Try

     MyInteger = Application.WorksheetFunction.Sum(MyIntegerArray)
    

    if Nick Sabbe’s suggestion that you place formulae in cells is inappropriate.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a PHP script which executes shell functions for reporting.
I am trying to write a VBA script which imports all of the Excel
I have been to trying to write some output to a CSV file using
The below is a part of a script i'm trying to write. The script
I am trying to write a script which will automate a copy/paste of employee
I have a Perl script, the relevant bits of which are posted below. #
I am trying to write a python script for Sieve of Eratosthenes. I have
I am trying to find a way to write a script which will check
I'm trying to write sql that produces the desired result from the data below.
(In short: main()'s WaitForSingleObject hangs in the program below). I'm trying to write a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.