It really sounds like you want a UDF. You cannot do something like "Range("A2").value=6" from a UDF. A function returns values to the spreadsheet through its name. It is somewhat unfortunate that you are trying something so complicated for your first UDF.

As starting place, I would first suggest you learn how to writ a simple UDF that returns one value to the spreadsheet. Something like:
function test1(arg1, arg2, arg3)
'code to perform desired calculations on arguments
'sample calculation
result=arg1*arg2+arg3
test1=result 'store result in test1 for return to spreadsheet
end function
called from the spreadsheet as =test1(A1,A2,A3)

What makes your question more complicated is that, in addition to the calculations you need to do, it sounds like you want the function to return multiple values to the spreadsheet. A UDF is easiest to program if it only returns one value. If the UDF must return multiple values, then you need to program it as an array function. To do this, you need to dimension "result" as an array, store each computation in this array, then return the array to the spreadsheet:
function arraytest(arg1,arg2,arg3)
dim result(1 to 2)
result(1)=arg1*arg2+arg3
result(2)=arg3*arg1+arg2
arraytest=result
end function
. In the spreadsheet, this will need to be entered as an array function (ctrl-shift-enter -- see the help files for other array functions like LINEST() or TRANSPOSE() for further examples of entering array functions) across the desired number of cells (my example returns 2 values). Note that, using a single dimensional array, the output will be a horizontal array of consecutive cells, so take that into consideration.

This is not a new topic. You might review previous topics like this one: http://www.excelforum.com/excel-prog...tion-call.html