Hi All,
I have a UDF that works fine until I make an edit in another workbook. On return to the workbook with the UDF, it is not calculating properly. A press of F9 will force correct calculation. I have the line Application.volatile at the start of the function. If I edit any cell in the workbook with the UDF, the formula will recalculate correctly.
Does anyone have any idea why switching between workbooks causes this issue? Function is shown below if it helps.
Many Thanks
Tom
I have a UDF that works fine until I make an edit in another workbook. On return to the workbook with the UDF, it is not calculating properly. A press of F9 will force correct calculation. I have the line Application.volatile at the start of the function. If I edit any cell in the workbook with the UDF, the formula will recalculate correctly.
Does anyone have any idea why switching between workbooks causes this issue? Function is shown below if it helps.
Many Thanks
Tom
Code:
Function markbookaverage()Application.Volatile
On Error GoTo errorhandler
Dim vol As Single, sum As Single, weight As Single
Dim myrow As Long
Dim desc As String
Dim gradedesc As String
Dim typer As String
vol = Application.WorksheetFunction.CountA(Range("L4:OU4"))
Set Rng = Application.Caller
For i = 1 To vol
gradedesc = Cells(6, 4 * i + 8)
desc = Cells(3, 4 * i + 8)
typer = Cells(6, 4 * i + 8)
If Cells(Rng.row, 4 * i + 11) = "" Then
Else
If Cells(Rng.row, 4 * i + 11).width < 0.1 Then
Else
If typer = "No_Grading" Then
Else
'Only multiples when worktype is 'weighted'
If desc = "Weighted" Then
weight = weight + Cells(41, 4 * i + 11)
sum = sum + Cells(Rng.row, 4 * i + 11) * Cells(41, 4 * i + 11)
Else
weight = weight + 1
sum = sum + Cells(Rng.row, 4 * i + 11)
End If
End If
End If
End If
Next i
markbookaverage = Round(sum / weight, 0) + 0
Application.Calculate
Exit Function
errorhandler:
If Err.Number = 11 Then
markbookaverage = "E"
Exit Function
Else
End If
Resume Next
End Function