Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Does VBA allow declaration of function which the user doesn't specify all the parameters for?
Example: Area("Triangle",sideA,sideB,sideC) Area("Rectangle",sideA,sideB) OR Area("Rectangle",sideA,sideB;) Area("Square",side) OR Area("Square",side;;) Thanks, Alex. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi
have a look at 'Optional' in the VBA help -- Regards Frank Kabel Frankfurt, Germany "y" schrieb im Newsbeitrag ... Does VBA allow declaration of function which the user doesn't specify all the parameters for? Example: Area("Triangle",sideA,sideB,sideC) Area("Rectangle",sideA,sideB) OR Area("Rectangle",sideA,sideB;) Area("Square",side) OR Area("Square",side;;) Thanks, Alex. |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
One way:
Public Function Area(sShapeType As String, _ ParamArray vSides() As Variant) As Double Select Case LCase(sShapeType) Case "triangle" If UBound(vSides) < 1 Then Area = CVErr(xlErrValue) Else Area = CDbl(vSides(0)) * CDbl(vSides(1)) / 2# End If Case "square" If UBound(vSides) < 0 Then Area = CVErr(xlErrValue) Else Area = CDbl(vSides(0)) ^ 2 End If Case "rectangle" If UBound(vSides) < 1 Then Area = CVErr(xlErrValue) Else Area = CDbl(vSides(0)) * CDbl(vSides(1)) End If Case "circle" If UBound(vSides) < 0 Then Area = CVErr(xlErrValue) Else Area = Application.Pi * vSides(0) ^ 2 End If Case Else Area = CVErr(xlErrValue) End Select End Function In article , y wrote: Does VBA allow declaration of function which the user doesn't specify all the parameters for? Example: Area("Triangle",sideA,sideB,sideC) Area("Rectangle",sideA,sideB) OR Area("Rectangle",sideA,sideB;) Area("Square",side) OR Area("Square",side;;) Thanks, Alex. |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks a lot!
|
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Custom or VBA Function for Avg, Std, Min, Max | Excel Discussion (Misc queries) | |||
Custom function | Excel Worksheet Functions | |||
Need Help with custom function! | Excel Worksheet Functions | |||
Emulate Index/Match combo function w/ VBA custom function | Excel Worksheet Functions | |||
Adding a custom function to the default excel function list | Excel Programming |