Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 599
Default 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



  #3   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default 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



.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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



  #5   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default 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



.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Default Windows Profile without default Office user info Karen Excel Discussion (Misc queries) 0 November 12th 08 04:53 PM
Default ribbon to open by default when opening xls in browser Hank Excel Discussion (Misc queries) 0 April 10th 08 10:12 PM
Functin to calculate arguments for a product? (12= 12*1, 4*3, 6*2. Excel Novice Excel Worksheet Functions 1 November 25th 06 10:38 PM
Average Functin Todd Excel Worksheet Functions 9 November 13th 06 05:27 PM
ISERROR Functin to Much Work! ExcelMonkey Excel Worksheet Functions 2 November 12th 04 08:47 PM


All times are GMT +1. The time now is 09:27 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"