C
Clare
Hi, I'm new to Excel vba. Could someone help to answer my questions on custom
functions and Application.Volatile ?
I hava custom function which looks something like below. It uses
theApplication.Volatile statement. My question is: With this code, if this
function are in two workbooks with identical structure (i.e. SAME worksheet
names, SAME columns for Grade, Criteria , but different values), are the
calculations safely isolated to each workbook ?
Function GRADECALC(rngGrade, strCriteria, rngScore)
Application.Volatile
Dim Results, GradeCount, ScoreSum
Dim rngR As Range
Dim rngS As Range
Set rngR = Range(rngGrade, rngGrade.End(xlDown))
Set rngS = Range(rngScore, rngScore.End(xlDown))
ScoreSum = Application.SumIf(rngR, strCriteria, rngS)
GradeCount = Application.CountIf(rngR, strCriteria)
If GradeCount = 0 Then
Results = "No Grade " & strCriteria & " found."
Else
If (GradeCount > 50) Then
Results = (ScoreSum / GradeCount) * 0.75
Else
Results = ScoreSum / GradeCount
End If
End If
GRADECALC = Results
End Function
Another thing, I saw a post by Niek Otten that says "if not all your data
comes into the function via the argument list, cells may still be calculated
in the wrong order".
Would this be applicable to the custom function above ? I have some doubts,
because the function gets the last cell and sets the ranges within the
function itself....
Thanks to anyone who can set me straight on this..
I'm using Excel 2003 on Win XP Pro btw.
Rgds,
Clare
functions and Application.Volatile ?
I hava custom function which looks something like below. It uses
theApplication.Volatile statement. My question is: With this code, if this
function are in two workbooks with identical structure (i.e. SAME worksheet
names, SAME columns for Grade, Criteria , but different values), are the
calculations safely isolated to each workbook ?
Function GRADECALC(rngGrade, strCriteria, rngScore)
Application.Volatile
Dim Results, GradeCount, ScoreSum
Dim rngR As Range
Dim rngS As Range
Set rngR = Range(rngGrade, rngGrade.End(xlDown))
Set rngS = Range(rngScore, rngScore.End(xlDown))
ScoreSum = Application.SumIf(rngR, strCriteria, rngS)
GradeCount = Application.CountIf(rngR, strCriteria)
If GradeCount = 0 Then
Results = "No Grade " & strCriteria & " found."
Else
If (GradeCount > 50) Then
Results = (ScoreSum / GradeCount) * 0.75
Else
Results = ScoreSum / GradeCount
End If
End If
GRADECALC = Results
End Function
Another thing, I saw a post by Niek Otten that says "if not all your data
comes into the function via the argument list, cells may still be calculated
in the wrong order".
Would this be applicable to the custom function above ? I have some doubts,
because the function gets the last cell and sets the ranges within the
function itself....
Thanks to anyone who can set me straight on this..
I'm using Excel 2003 on Win XP Pro btw.
Rgds,
Clare