I've copied below an exchange we had in the group a while back that
should get you started on this custom function.
To pass a cell value to VBA and back is quite straightforward, but made
immensely easier if you give the cell a range name first. For instance,
on a sheet called Front sheet, the cell at A5 is given the range name
This_One. Its value can be passed to a VBA variable valled varValue with
this line:
varValue=Sheets("Front sheet").Range("This_One").Value
You can write it back to the cell like this:
Sheets("Front sheet").Range("This_One").Value=varValue