我有以下代码:它工作正常,但我想要改善它的代码的最后部分,如果contador = 0,我想要mespt =“没有本质considera”,而不仅仅是返回0。VBA Excel-函数返回一个数字或字符串
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下列方式使用变种:
Funcion mespt( ) as Variant
.......
if contador = 0 then
mespt="No se considera" then
mespt=totalmespt/contador
end if
end function
但在康塔多的情况下= 0时,该功能只是返回#!Valor
对不起,机智h变种类型它的工作流程OK,正如我所期望的那样,问题只是在excel中使用函数mespt的公式。
如何返回为Varient。 – JSJ
@jsj:这是一个有效的答案。 :)你可能想把它作为答案? –
请在我的帖子中查看我的代码的执行情况以及您的建议,但不幸运。 – CreamStat