"Object Required" when calling function in sub in VBA Excel
12,645
You don't need the keyword Set
for the type String, that's why.
Unlike to other programming languages, VBA considers String as a Data Type, and not as an Object.
The keyword Set
is used to assign a reference to an object (Worksheet, Range, etc...).
If you try to assign a reference to a data type, as you did, you will get an error.
Author by
user1143529
Updated on June 14, 2022Comments
-
user1143529 almost 2 years
In my VBA program for excel; I have a function called "ParamCheck" which get four "double" variables, checks them and returns a message as "string".
Function ParamCheck(airSpeed As Double, FCUvalue As Double, _ altitude As Double, terrainElevation As Double) As String If airSpeed < MIN_CONTROL_SPEED Then 'check if airspeed is less than 119 ft/min or not ParamCheck = "Airspeed is less than minimum control speed" ElseIf FCUvalue > FCU_VALUE_LIMIT Then 'check if FCU value if greater than 10 or not ParamCheck = "FCU value is greater than limit" ElseIf FCUvalue < 0 Then 'check if FCU vlaue is negative or not ParamCheck = "FCU value is negative" ElseIf altitude <= terrainElevation Then 'check if altitude is greater that terrain of elevation or not ParamCheck = "Altitude is less than terrain elevation" Else 'if all the parameters are valid print a "Valid" message ParamCheck = PARAMS_OK End If End Function
and now I need to call this function in my sub program. Here is the code
Dim checkParam As String ' result of validity check of parameters Set checkParam = ParamCheck(speedAir, valueFCU, aboveSea, elevationTerrain)
when running it gives me this error "object required" and highlights "checkParam"