ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   SUM Function Yields Zero Result (https://www.excelbanter.com/excel-programming/301833-sum-function-yields-zero-result.html)

ELLIEOL

SUM Function Yields Zero Result
 
I tried to use the SUM function in VBA. I had used similar code successfully before, but now get a zero result, even if there are non-zero numbers in the range. Here's the code. Of course, nRow, nCol and NumColsOutput have been previously defined.

Set zRange = .Range(.Cells(nRow, nCol), .Cells(nRow, NumColsOutput))
Sum = WorksheetFunction.Sum(zRange)

If I use "zRange.Select", I can see that it is selecting the desired range of cells, so the Range works correctly, yet the SUM is wrong.

I then tried the simple worksheet function, entered into a cell: =SUM(A1:D3)

I found that sometimes I got a zero result, sometimes a non-zero result.

Can anyone suggest why I might be getting these "false" zero results from the SUM function?

Thank you very much for any help you may be able to offer.


Pete McCOsh

SUM Function Yields Zero Result
 
If there's always data in the range when you're using =sum
then it must be formatted as text. Are you importing data
from somewhere else? You get this kind of problem
sometimes if you're pulling data from Crystal Reports, but
I don't know about anything else.

Pete.

-----Original Message-----
I tried to use the SUM function in VBA. I had used

similar code successfully before, but now get a zero
result, even if there are non-zero numbers in the range.
Here's the code. Of course, nRow, nCol and NumColsOutput
have been previously defined.

Set zRange = .Range(.Cells(nRow, nCol), .Cells(nRow,

NumColsOutput))
Sum = WorksheetFunction.Sum(zRange)

If I use "zRange.Select", I can see that it is selecting

the desired range of cells, so the Range works correctly,
yet the SUM is wrong.

I then tried the simple worksheet function, entered into

a cell: =SUM(A1:D3)

I found that sometimes I got a zero result, sometimes a

non-zero result.

Can anyone suggest why I might be getting these "false"

zero results from the SUM function?

Thank you very much for any help you may be able to offer.

.



All times are GMT +1. The time now is 04:34 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com