I have the following code: It´s working OK but what I want to improve it´s in the final part of the code, if contador = 0, I want mespt="No se considera" instead of just returning 0.
Public Function mespt(tutor As String, mes As String, j As Long) As Double
Application.Volatile
Dim a As Long
Dim totalmesp As Double
mespt = 0
contador = 0
totalmespt = 0
For i = 4 To 1000
If Sheets("Hoja1").Cells(i, 2).FormulaR1C1 = tutor And Sheets("Hoja1").Cells(i, 5).FormulaR1C1 = mes Then
Select Case Sheets("Hoja1").Cells(i, j).Value
Case "No cumple"
a = 0
contador = contador + 1
Case "Regular"
a = 1
contador = contador + 1
Case "Pleno"
a = 3
contador = contador + 1
Case "No se considera"
a = 0
End Select
totalmespt = totalmespt + a
If contador = 0 Then
mespt = 0
Else
mespt = totalmespt / contador
End If
End If
Next
End Function
I`ve used with variant in the following way:
Funcion mespt( ) as Variant
.......
if contador = 0 then
mespt="No se considera" then
mespt=totalmespt/contador
end if
end function
But in the case contador=0, the function just returns #!Valor
Sorry, with the variant type it's workink OK as I expect now, the problem was just with a formula in excel which works with the function mespt.