Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 64
Default 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.

.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Month function yields incorrect solution alwein Excel Worksheet Functions 4 December 16th 08 01:34 AM
Production Yields HW New Users to Excel 2 June 11th 08 11:59 PM
Substitute function yields #VALUE! when add the instance_number Bob F Excel Worksheet Functions 7 November 30th 07 03:08 AM
Need help with bond yields Jerel Excel Discussion (Misc queries) 4 February 7th 07 07:40 PM
ACCRINT formula yields incorrect result Onurali_k Excel Worksheet Functions 7 March 24th 05 05:47 PM


All times are GMT +1. The time now is 07:45 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"