#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default SUM in VBA

In the worksheet:
=SUM(Sheet1!A1:Sheet1!A13)
works just fine, giving the sum of cells.
In VBA:
Dim i As Variant
i = Application.SUM(Sheet1!A1:Sheet1!A13) just give a compile error.

Why?
--
Gary's Student
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default SUM in VBA



i = Application.Sum(Worksheets("Sheet1").Range("A1:A13 "))

"Gary''s Student" wrote:

In the worksheet:
=SUM(Sheet1!A1:Sheet1!A13)
works just fine, giving the sum of cells.
In VBA:
Dim i As Variant
i = Application.SUM(Sheet1!A1:Sheet1!A13) just give a compile error.

Why?
--
Gary's Student

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default SUM in VBA

Try this:

i = WorksheetFunction.Sum(Range("Sheet1!A1:Sheet1!A13" ))

"Gary''s Student" wrote:

In the worksheet:
=SUM(Sheet1!A1:Sheet1!A13)
works just fine, giving the sum of cells.
In VBA:
Dim i As Variant
i = Application.SUM(Sheet1!A1:Sheet1!A13) just give a compile error.

Why?
--
Gary's Student

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default SUM in VBA

VBA works on a range object,

i = Application.SUM(Range("Sheet1!A1:Sheet1!A13")

--

HTH

Bob Phillips

(remove nothere from the email address if mailing direct)

"Gary''s Student" wrote in message
...
In the worksheet:
=SUM(Sheet1!A1:Sheet1!A13)
works just fine, giving the sum of cells.
In VBA:
Dim i As Variant
i = Application.SUM(Sheet1!A1:Sheet1!A13) just give a compile error.

Why?
--
Gary's Student



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default SUM in VBA

Try this:

Sub test()
Dim myrange As Range
Dim i As Variant
Set myrange = Worksheets("Sheet1").Range("A1:A13")
i = Application.WorksheetFunction.Sum(myrange)
End Sub

"Bob Phillips" wrote:

VBA works on a range object,

i = Application.SUM(Range("Sheet1!A1:Sheet1!A13")

--

HTH

Bob Phillips

(remove nothere from the email address if mailing direct)

"Gary''s Student" wrote in message
...
In the worksheet:
=SUM(Sheet1!A1:Sheet1!A13)
works just fine, giving the sum of cells.
In VBA:
Dim i As Variant
i = Application.SUM(Sheet1!A1:Sheet1!A13) just give a compile error.

Why?
--
Gary's Student




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



All times are GMT +1. The time now is 10:58 AM.

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"