![]() |
Default Value For Functin
Hello to all,
I am trying to program a function that has two input parameter, but i dont want one of the to be absolutly necessary. I want it to have a default value in case I dont put it on the function sintaxis. So far i have my funciton done but i have to input both values. i.e. MyFunction(MyVal,Unit as String) I want to be able to use it as =MyFunction(MyVal)and have a default unit such as "Kg" but beeing able to also write de function as =MyFunction(MyVal,"Lb") Any help would ve highly appreciate. Regards JS |
Default Value For Functin
Juan
Function MyFunction(MyVal as Double, Optional Unit as String = "Kg") As Double I added the 'as Double' parts, but they are just guesses. You should explicity declare the data types for your arguments and your return value. -- Dick Kusleika MVP - Excel www.dicks-clicks.com Post all replies to the newsgroup. "Juan" wrote in message ... Hello to all, I am trying to program a function that has two input parameter, but i dont want one of the to be absolutly necessary. I want it to have a default value in case I dont put it on the function sintaxis. So far i have my funciton done but i have to input both values. i.e. MyFunction(MyVal,Unit as String) I want to be able to use it as =MyFunction(MyVal)and have a default unit such as "Kg" but beeing able to also write de function as =MyFunction(MyVal,"Lb") Any help would ve highly appreciate. Regards JS |
Default Value For Functin
MyFunction(MyVal,Optional Unit as String = "Kg")
Function MyFunction(MyVal, Optional Unit As String = "Kg") MyFunction = Unit End Function Sub TesterAA() res = MyFunction(10) res1 = MyFunction(10, "lb") Debug.Print res, res1 End Sub returned Kg lb -- Regards, Tom Ogilvy "Juan" wrote in message ... Hello to all, I am trying to program a function that has two input parameter, but i dont want one of the to be absolutly necessary. I want it to have a default value in case I dont put it on the function sintaxis. So far i have my funciton done but i have to input both values. i.e. MyFunction(MyVal,Unit as String) I want to be able to use it as =MyFunction(MyVal)and have a default unit such as "Kg" but beeing able to also write de function as =MyFunction(MyVal,"Lb") Any help would ve highly appreciate. Regards JS |
Default Value For Functin
THANKS TOM!
-----Original Message----- MyFunction(MyVal,Optional Unit as String = "Kg") Function MyFunction(MyVal, Optional Unit As String = "Kg") MyFunction = Unit End Function Sub TesterAA() res = MyFunction(10) res1 = MyFunction(10, "lb") Debug.Print res, res1 End Sub returned Kg lb -- Regards, Tom Ogilvy "Juan" wrote in message ... Hello to all, I am trying to program a function that has two input parameter, but i dont want one of the to be absolutly necessary. I want it to have a default value in case I dont put it on the function sintaxis. So far i have my funciton done but i have to input both values. i.e. MyFunction(MyVal,Unit as String) I want to be able to use it as =MyFunction(MyVal)and have a default unit such as "Kg" but beeing able to also write de function as =MyFunction(MyVal,"Lb") Any help would ve highly appreciate. Regards JS . |
Default Value For Functin
THANKS DICK!
-----Original Message----- Juan Function MyFunction(MyVal as Double, Optional Unit as String = "Kg") As Double I added the 'as Double' parts, but they are just guesses. You should explicity declare the data types for your arguments and your return value. -- Dick Kusleika MVP - Excel www.dicks-clicks.com Post all replies to the newsgroup. "Juan" wrote in message ... Hello to all, I am trying to program a function that has two input parameter, but i dont want one of the to be absolutly necessary. I want it to have a default value in case I dont put it on the function sintaxis. So far i have my funciton done but i have to input both values. i.e. MyFunction(MyVal,Unit as String) I want to be able to use it as =MyFunction(MyVal)and have a default unit such as "Kg" but beeing able to also write de function as =MyFunction(MyVal,"Lb") Any help would ve highly appreciate. Regards JS . |
All times are GMT +1. The time now is 09:43 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com