View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Martin Fishlock[_4_] Martin Fishlock[_4_] is offline
external usenet poster
 
Posts: 32
Default Range object in Worksheetfunction.Sum

Nuraq,

I think that you have misspelt criteriascore. Try using option explicit to
catch the error.

Otherwise you may not be referencing the cells correctly and explicitlty
reference the cells as in the code below:
.....
Worksheets("DecisionScores").Cells(3, 2)
....

This is my try:

Option Explicit

Function CriteriaScore() As Integer
Dim MyRange As Range
Set MyRange = Worksheets( _
"DecisionScores").Range(Worksheets("DecisionScores ").Cells(3, 2), _
Worksheets("DecisionScores").Cells(3, 6))
CriteriaScore = WorksheetFunction.Sum(MyRange)
Set MyRange = Nothing
End Function


--
HTHs Martin


"Nuraq" wrote:

I am trying to return the sum of a range using a function "CriteriaScore".
Iam tryin to use the Cells object to specify the Range, but VB is not happy.
If I define the function as follows, it works fine:

Function CriteriaScore () As Integer
Set MyRange = Worksheets("DecisionScores").Range("B3:F3")
CiteriaScore = WorksheetFunction.Sum(MyRange)
End Function

However, as soon as I introduce the Cells reference, it doens't work:

Function CriteriaScore () As Integer
Set MyRange = Worksheets("DecisionScores").Range(Cells(3, 2), Cells(3,
6))
CiteriaScore = WorksheetFunction.Sum(MyRange)
End Function

Any ideas?