PDA

View Full Version : Solved: Problem with setting Range, and calculating SUM



chris111
09-02-2010, 07:30 AM
Hi,

I'm trying to sum up a series of numbers on the active workbook using the application.worksheetfunction command..

My code is:


Set shares = ActiveWorkbook.Sheets("volume").Range(Cells(i + 1, testseccol), Cells(i + 252, testseccol))
twelvemshares = Application.WorksheetFunction.Sum(shares)


The variables are defined like:
shares as range
i, testseccol as integer
twelvemshares as variant

The values passed into the code are i=1, testseccol=167

The problem is "shares" doesn't get assigned the range, and thus there is nothing to sum.. Can someone help me define this range correctly, or have another idea how to sum these numbers?

mohanvijay
09-02-2010, 07:45 AM
Try this




Set shares = ActiveWorkbook.Sheets("volume").Range(Cells(i + 1, testseccol).Address, Cells(i + 252, testseccol).Address)
twelvemshares = WorksheetFunction.Sum(shares)

chris111
09-02-2010, 07:49 AM
Works like a charm!

Thank you