Results 1 to 4 of 4
  1. #1
    2 Star Lounger
    Join Date
    Jan 2004
    Posts
    196
    Thanks
    1
    Thanked 0 Times in 0 Posts

    'SUM' in code (2003)

    I am looking for a way to sum a range within code?????

    I want to do something like, worksheets(3).sum(D3844)
    instead of worksheets(3).range("D38")+worksheets("D39")+...

    Please help...

    thanks,
    jackal

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: 'SUM' in code (2003)

    You can use

    Dim dblSum As Double
    dblSum = Application.WorksheetFunction.Sum(Worksheets(3).Ra nge("D3844"))

    Note that Sum is not a method of the Worksheet object, but of the Application.WorksheetFunction object, and that you must specify the sheet+range as argument to Sum.

  3. #3
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: 'SUM' in code (2003)

    In addition to Worksheetfunction as in Hans' reply, you could also do something like this:

    <code>
    Dim dSum As Double, oCell As Range
    dSum = 0
    For Each oCell In Worksheets(3).Range("D3844")
    If IsNumeric(oCell.Value) Then
    dSum = dSum + oCell.Value
    End If
    Next oCell
    </code>
    Legare Coleman

  4. #4
    2 Star Lounger
    Join Date
    Jan 2004
    Posts
    196
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: 'SUM' in code (2003)

    thanks Hans, that is just what i was looking for...

    thanks,
    jackal

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •