ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Loop w/ Public Function as arguement (https://www.excelbanter.com/excel-programming/376333-loop-w-public-function-arguement.html)

wienmichael

Loop w/ Public Function as arguement
 
I am trying to create a loop to count how many times a date function I have
written is performed before a criteria is met. I am receiving a ByRef error,
and do no know how to fix it. Here is the code:

Public Function myfunc(testdate, maturitydate)
counter = 0
Do While maturitydate testdate
testdate = nextcdate(testdate)
counter = counter + 1
Loop
myfunc = counter
End Function

Thanks

NickHK

Loop w/ Public Function as arguement
 
Hard to tell without the signature of the function "nextcdate".
Also, it would be more clear if you declared data types in the arguments and
return value of the functions. Maybe, it is:

Public Function myfunc(testdate as date, maturitydate as date) as long

Also, read the Help on the difference between "ByRef" and "ByVal" arguments.
Note "ByRef" is the default.
Depending on where this is called from and how you intend these functions to
be used, you may be changing values inadvertently.

NickHK

"wienmichael" wrote in message
...
I am trying to create a loop to count how many times a date function I

have
written is performed before a criteria is met. I am receiving a ByRef

error,
and do no know how to fix it. Here is the code:

Public Function myfunc(testdate, maturitydate)
counter = 0
Do While maturitydate testdate
testdate = nextcdate(testdate)
counter = counter + 1
Loop
myfunc = counter
End Function

Thanks




Bob Phillips

Loop w/ Public Function as arguement
 
It look as if nextcdate has typed arguments, such as

Function nextcdate(inDate as Date)

but you are trying to pass a variant to it.

Declare the types of the myfunc function and ensure that they all match. It
is far better to declare the type of an argument, even if you intend for it
to be variant.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"wienmichael" wrote in message
...
I am trying to create a loop to count how many times a date function I

have
written is performed before a criteria is met. I am receiving a ByRef

error,
and do no know how to fix it. Here is the code:

Public Function myfunc(testdate, maturitydate)
counter = 0
Do While maturitydate testdate
testdate = nextcdate(testdate)
counter = counter + 1
Loop
myfunc = counter
End Function

Thanks





All times are GMT +1. The time now is 01:07 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com