![]() |
Calling Function
How can I call a custom function without VBA asking me to assign it to variable? Ex: Sub test() customFunction(arg1,arg2) end Sub is there any way to do this without msgboxing it or assigning it? Cheer -- mattsva ----------------------------------------------------------------------- mattsvai's Profile: http://www.excelforum.com/member.php...fo&userid=3113 View this thread: http://www.excelforum.com/showthread.php?threadid=51181 |
Calling Function
Remove "Option Explicit" at the top of the module
The general syntax of a variable declaration is: Dim VariableName As DataType If a particular variable is used without first declaring it, or if it is declared without mentioning a data type, as in: Dim Age then VBA will treat the variable as having type Variant. this is generally a waste of memory, since variants require more memory than most other types of variables. I always decler variable, then you now wich data type it is. Regard Yngve |
Calling Function
customFunction(arg1,arg2)
Hi. With your use of ( ), the function is expecting to return a value. Try it without the use of ( ). Sub TestIt() Dim arg1, arg2 CustomFunction arg1, arg2 'or.. Call CustomFunction(arg1, arg2) End Sub Function CustomFunction(x, y) CustomFunction = x * y End Function -- HTH. :) Dana DeLouis Windows XP, Office 2003 "mattsvai" wrote in message ... How can I call a custom function without VBA asking me to assign it to a variable? Ex: Sub test() customFunction(arg1,arg2) end Sub is there any way to do this without msgboxing it or assigning it? Cheers -- mattsvai ------------------------------------------------------------------------ mattsvai's Profile: http://www.excelforum.com/member.php...o&userid=31134 View this thread: http://www.excelforum.com/showthread...hreadid=511819 |
Calling Function
I entered the following:
Sub TestIt() arg1 = Range("b6").Value arg2 = Range("B10").Value CustomFunction arg1, arg2 MsgBox "The Answer is " & CustomFunction << But I get Compile error here!! Why? End Sub Function CustomFunction(x, y) CustomFunction = x * y End Function "Dana DeLouis" wrote: customFunction(arg1,arg2) Hi. With your use of ( ), the function is expecting to return a value. Try it without the use of ( ). Sub TestIt() Dim arg1, arg2 CustomFunction arg1, arg2 'or.. Call CustomFunction(arg1, arg2) End Sub Function CustomFunction(x, y) CustomFunction = x * y End Function -- HTH. :) Dana DeLouis Windows XP, Office 2003 "mattsvai" wrote in message ... How can I call a custom function without VBA asking me to assign it to a variable? Ex: Sub test() customFunction(arg1,arg2) end Sub is there any way to do this without msgboxing it or assigning it? Cheers -- mattsvai ------------------------------------------------------------------------ mattsvai's Profile: http://www.excelforum.com/member.php...o&userid=31134 View this thread: http://www.excelforum.com/showthread...hreadid=511819 |
Calling Function
Never mind,,, Figured it Out!!
Corrected as follows: Sub TestIt() arg1 = Range("b6").Value arg2 = Range("B10").Value MyAnswer = CustomFunction(arg1, arg2) MsgBox "The Answer is " & MyAnswer End Sub Function CustomFunction(x, y) CustomFunction = x * y End Function "Jim May" wrote in message ... I entered the following: Sub TestIt() arg1 = Range("b6").Value arg2 = Range("B10").Value CustomFunction arg1, arg2 MsgBox "The Answer is " & CustomFunction << But I get Compile error here!! Why? End Sub Function CustomFunction(x, y) CustomFunction = x * y End Function "Dana DeLouis" wrote: customFunction(arg1,arg2) Hi. With your use of ( ), the function is expecting to return a value. Try it without the use of ( ). Sub TestIt() Dim arg1, arg2 CustomFunction arg1, arg2 'or.. Call CustomFunction(arg1, arg2) End Sub Function CustomFunction(x, y) CustomFunction = x * y End Function -- HTH. :) Dana DeLouis Windows XP, Office 2003 "mattsvai" wrote in message ... How can I call a custom function without VBA asking me to assign it to a variable? Ex: Sub test() customFunction(arg1,arg2) end Sub is there any way to do this without msgboxing it or assigning it? Cheers -- mattsvai ------------------------------------------------------------------------ mattsvai's Profile: http://www.excelforum.com/member.php...o&userid=31134 View this thread: http://www.excelforum.com/showthread...hreadid=511819 |
All times are GMT +1. The time now is 05:35 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com