Function Calling Subroutine

  • Thread starter Thread starter Curare
  • Start date Start date
C

Curare

I am new to VB coding and trying to develop a few tools to make lif
easier for myself. Currently, I am trying to insert values in a table
user-inputs fields for results. After the inputs, I want to look up
results according to age. For a test run I am trying some coding in
simple form, as shown below:

Function TestRun(AnyNo As Integer)
Call TRun(AnyNo)
TestRun = Range("A7")
End Function

Sub TRun(AnyNo)
Range("A7") = AnyNo
End Sub

This works when I run it in the Immidiate Window but not on th
worksheet. Is there a certain setup in excel that I need checke
before this method can work? If no, are there altervatives for such a
method to work? Thanks
 
Hi
the problem is that functions are not allowed to change any cells /
formats / etc. They can only return values. But in your code you're
calling a sub which changes a cell. This is not allowed. Therefor the
code
Function TestRun(AnyNo As Integer)
TestRun = Range("A7").value *AnyNo
End Function

would work
 
Thanks Frank. Since the function will not allow cell chnages than
will have to fugure out some other way to get the results. I a
dealing with mortality tables that are affected by interest rates an
various other parameters. I was trying this to avoid coding th
formulae into the functions, but it may be the only choice I have
Thanks again for your input
 
Back
Top