summing up values in an excel spreadsheet


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: summing up values in an excel spreadsheet

  1. #1
    Naveen Guest

    summing up values in an excel spreadsheet


    Hi

    Could some one tell me which method i could use to sum up values in certain
    columns in an excel spreadsheet.

    Note that these excel spreadsheets are created dynamically .

    Thanks in advance
    Naveen

  2. #2
    Martin Rydman Guest

    Re: summing up values in an excel spreadsheet


    Naveen,

    By 'created dynamically', I assume you don't know how many cells/columns
    you'll be dealing with. The basic tool for this problem is the CurrentRegion
    property of the Range object. It will scan adjacent cells of a particular
    cell and return a range with all cells around it with values in them. (Try
    it out with CTRL-SHIFT-* to see what I mean). I've put together a general
    purpose function that takes a single cell as parameter and returns the sum
    of all cells in the original cell's CurrentRegion (should work fine for columns
    as well):

    'Sums all cells in the 'current region' of the cell regerneced by
    'the parameter Rng
    Public Function SumRange(ByVal Rng As Range) As Double

    Dim Cell As Range
    Dim Sum As Double

    Set Rng = Rng.CurrentRegion

    For Each Cell In Rng
    Sum = Sum + Cell.Value
    Next

    SumRange = Sum
    End Function


    HTH

    /Martin



    >
    >Hi
    >
    >Could some one tell me which method i could use to sum up values in certain
    >columns in an excel spreadsheet.
    >
    >Note that these excel spreadsheets are created dynamically .
    >
    >Thanks in advance
    >Naveen



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center