Restricting values for an argument in UDF

dfoakley

New Member
Joined
Jul 16, 2013
Messages
3
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

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?
 

Some videos you may like

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

Watch MrExcel Video

Forum statistics

Threads
1,122,850
Messages
5,598,455
Members
414,239
Latest member
xnanx

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top