ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Using a function (https://www.excelbanter.com/excel-discussion-misc-queries/111417-using-function.html)

Jeff

Using a function
 
Hi,

I want a function to return a value, but it is not working. Here is my code.

Sub NewTest()
v = 1: j = 9
x = TestFunction(v, j)
End Sub

Sub TestFunction(x, y)
TestFunction = x ^ 2 + y
End Sub

Error Message = "compile error, expected function or variable",
highligted -- "x = TestFunction(v, j)"
Does anyone know how to fix this?

Thanks for your help.

Gary''s Student

Using a function
 
use

Function TestFunction(x, y)

rather than

Sub TestFunction(x, y)
--
Gary''s Student


"Jeff" wrote:

Hi,

I want a function to return a value, but it is not working. Here is my code.

Sub NewTest()
v = 1: j = 9
x = TestFunction(v, j)
End Sub

Sub TestFunction(x, y)
TestFunction = x ^ 2 + y
End Sub

Error Message = "compile error, expected function or variable",
highligted -- "x = TestFunction(v, j)"
Does anyone know how to fix this?

Thanks for your help.


Jeff

Using a function
 
Duh!

I should have seen that -

Thanks

"Gary''s Student" wrote:

use

Function TestFunction(x, y)

rather than

Sub TestFunction(x, y)
--
Gary''s Student


"Jeff" wrote:

Hi,

I want a function to return a value, but it is not working. Here is my code.

Sub NewTest()
v = 1: j = 9
x = TestFunction(v, j)
End Sub

Sub TestFunction(x, y)
TestFunction = x ^ 2 + y
End Sub

Error Message = "compile error, expected function or variable",
highligted -- "x = TestFunction(v, j)"
Does anyone know how to fix this?

Thanks for your help.





All times are GMT +1. The time now is 11:59 PM.

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