# Sum of an Array

1. ## 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. ## 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.``

3. ## 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?

4. ## 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. ## Re: Sum of an Array

Originally Posted by Norie
Nicholas

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

do I need to declare a datatype with these?

6. ## 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. ## 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. ## 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.

#### Thread Information

##### Users Browsing this Thread

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

#### 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