我怎样才能显示一个string从一个函数返回一个double

我有一个非常简单的VBA函数,它使用两个范围参数,并使用两个范围的值返回一个double。 我在单个单元格的公式栏中使用这个,但是我想要返回一个string错误,如果不是很正确的话。 有没有一种方法,我可以显示这个没有显示#VALUE在单元格?

Public Function CPP(aPreviousPercentage As Range, aCurrentPercentage As Range) As Double If (aPreviousPercentage.Value > 0.2) Then CPP = "Invalid Starting Value" Exit Function End If CPP = aCurrentPercentage.Value - aPreviousPercentage.Value End Function 

可能最好的方法是将返回types更改为变体而不是双。 这样,如果你想你可以将其设置为一个string,而不是一个数字值。

 Public Function CPP(aPreviousPercentage As Range, aCurrentPercentage As Range) As Variant