Using the Sum Function in VBA

T

Theresa Simpson

Hello:

I am trying to use the sum function in a VBA module in an
excel 2002 worksheet. When my code runs, it seems to not
recognize the "Sum" function. Any suggestions as to why
it is not being recognized would be appreciated. Is
there a small line of code that I might be missing that
would allow me to use this or any function?

Thanks,

Theresa
 
J

jaf

Hi Theresa,
There isn't a SUM function in VBA.
You can use application.worksheetfunction.sum(1,2,3,4).

Or do it the easy way.
=1+2+3+4



--
John
johnf 202 at hotmail dot com


| Hello:
|
| I am trying to use the sum function in a VBA module in an
| excel 2002 worksheet. When my code runs, it seems to not
| recognize the "Sum" function. Any suggestions as to why
| it is not being recognized would be appreciated. Is
| there a small line of code that I might be missing that
| would allow me to use this or any function?
|
| Thanks,
|
| Theresa
 
G

Guest

No, I wasn't. Thank you very much. My problem now is
that it is summing incorrectly. I have looked at decimal
places etc. There is nothing else that could be adding
in that I can find anywhere. If I do a sum at the end of
the column I get 1 total, the code produces another total.

Scratching my head, totally baffled. !!!!
 
T

Theresa Simpson

No, I wasn't. Thank you very much. My problem now is
that it is summing incorrectly. I have looked at decimal
places etc. There is nothing else that could be adding
in that I can find anywhere. If I do a sum at the end of
the column I get 1 total, the code produces another total.

Scratching my head, totally baffled. !!!!
 
R

Rob van Gelder

Theresa,

Try to gather more information on the problem.
Start by summing just one value and compare. Then two, then three etc until
you identify the cells which are contributing to the problem.

Rob
 
K

KJTFS

I suggest setting up a loop that goes thru each cell and displays the
value in the cell you are adding, like a msgbox or just use a watch
variable... See what the cells have in them you are adding then add
them on a calculator. That should put you on the track as to what VBA
is doing also make sure the variable you are using to store the sum in
declared as in dim dblMySum as double and dblMySum = 0 .

Hope that gets you closer to your answer.

Keith
www.kjtfs.com
 
G

Guest

Hi Theresa

You mentioned looking at decimals. Have you checked whether you've declared all your 'to-be-summed' and your sum variables as Single or Double

SuperJas.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top