2021年4月5日星期一

Excel VBA returns Value Used in the formula is of wrong data type

I want a create a user defined function in excel. That converts a value based on input unit. But I get an error if the final result is lower than 1. Function

Function ConvertQtyToMeterPerSecs(qty As Double, unit As String) As Double    Dim ck As Double     'Converting all to m3/secs    If (unit = "cm/hr") Then  ck = qty * ((1 / 100) / (60 * 60))  ElseIf (unit = "cm/day") Then  ck = qty * ((1 / 100) / (24 * 60 * 60))  ElseIf (unit = "cm/sec") Then  ck = qty * (1 / 100)  ConvertQtyToMeterPerSecs=ck  End Function  

When I call the function in a cell in excel it works fine but it will throw an error if for example the result is 0.32444

https://stackoverflow.com/questions/66962198/excel-vba-returns-value-used-in-the-formula-is-of-wrong-data-type April 06, 2021 at 11:05AM

没有评论:

发表评论