+ Reply to Thread
Results 1 to 8 of 8

Sum of an Array

  1. #1
    Registered User
    Join Date
    06-01-2013
    Location
    United States
    MS-Off Ver
    Excel 2011
    Posts
    64

    Sum of an Array

    So I've never used arrays before but I read through some tutorials but I'm getting some errors.
    So the first bit of code is really what I'm trying to accomplish and the second bit I was experimenting to try to learn.
    Looking at the first bit of code, what I need is to run through a column of numbers. If the number is positive then add it to the posArray array and if it's negative at it to the negArray array. Then once all the numbers have been added to the appropriate arrays, I need to generate two different sums.
    If you could help out with two requests here is what they are:
    1.) how would I set a cell equal to the sum of an array?
    2.) what would it look like if I used the sum of the array in the code and performed more calculations before I set a cell equal to the value -- for example, in the code I would take the sum of posArray. Then I would calculate 100-1/posArray and put that calculation in a cell? Maybe I should just set he sum of the array equal to a variable?

    Thanks for your time!

    Please Login or Register  to view this content.

    Please Login or Register  to view this content.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Sum of an Array

    Nicholas

    For the first part.
    Please Login or Register  to view this content.
    For the second part add this to the code.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  3. #3
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Sum of an Array

    Hey Norie, won't idxpos always be 0 with your example?

    EDIT never mind, I see it's increment

    Where's my glasses?
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

  4. #4
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Sum of an Array

    Does this do the same as Norie's? Not sure but it's what I was working on
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    06-01-2013
    Location
    United States
    MS-Off Ver
    Excel 2011
    Posts
    64

    Re: Sum of an Array

    Quote Originally Posted by Norie View Post
    Nicholas

    For the first part.
    Please Login or Register  to view this content.

    do I need to declare a datatype with these?

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Sum of an Array

    Well, you could, but it wouldn't be string and unless you know exactly what data you have it would be hard to pick the correct numeric data type.

  7. #7
    Registered User
    Join Date
    06-01-2013
    Location
    United States
    MS-Off Ver
    Excel 2011
    Posts
    64

    Re: Sum of an Array

    Okay, thanks.
    And the "Option Explicit" piece -- what does that do? I deleted it and the code seems to do the same thing? haha.

  8. #8
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Sum of an Array

    Leave it in.

    What it does is force variable declaration, which is a good thing.

    It actually picked up a few typos in the code I posted, before I posted it.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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