I've made a custom unit conversion function to include units not included with the CONVERT function in excel. The gist of the code is below
As you can see, this requires that the class argument matches the values in the lookup arrays exactly. Is there a way I can restrict this value in the function definition? For example, the "Lookup Type" argument in the standard HLOOKUP and VLOOKUP functions is restrict to TRUE/FALSE, and a screentip shows up as you type that argument; is there a way to do something similar with a custom function?
Code:
Option Explicit
Function Conv(Amount As Double, Class As String) As Variant
Dim factor As Double, A(57,1) As Variant, B(13,1) As Variant, UnitType As String, i As Double, j as Double
'...Array containing valid unit names and conversion factors, this is Array "A" in the definitions'
'...Array containing valid unit classes, this is Array "B" in the definitions'
For i = 0 to 13
If B(i,0) = class Then
UnitType = B(i,1)
Exit For
End If
Next i
For j = 0 to 57
If A(j,0)=UnitType Then
factor = A(j,1)
Exit For
End If
Next j
Conv = factor * Amount
End Function
As you can see, this requires that the class argument matches the values in the lookup arrays exactly. Is there a way I can restrict this value in the function definition? For example, the "Lookup Type" argument in the standard HLOOKUP and VLOOKUP functions is restrict to TRUE/FALSE, and a screentip shows up as you type that argument; is there a way to do something similar with a custom function?