View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default Sum a column of data

There is no difference.

Not true; there is a difference when it comes to error handling. If you
omit the "WorksheetFunction", you can trap the error in a Variant and test
that with IsError. If you include "WorksheetFunction", you must trap a
run-time error with an On Error statement.

Sub AAA()
Dim V As Variant
V = Application.Sum(Range("A1:A3"))
If IsError(V) = True Then
Debug.Print "ERROR USING SUM"
Else
Debug.Print CStr(V)
End If

On Error Resume Next
Err.Clear
V = Application.WorksheetFunction.Sum(Range("A1:A3"))
If Err.Number < 0 Then
Debug.Print "ERROR USING SUM"
Else
Debug.Print CStr(V)
End If
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)

"Zone" wrote in message
...
There is no difference.

"cubbybear3" wrote in message
ups.com...
Okay, now I have a question for the experts.
What are the pros/cons/differences between:

Total=WorksheetFunction.Sum(...)
and
Total=Application.Sum(...)

Thanks, I'm just trying to learn more about VBA programming.
-pb