Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Method to recalculate functions in cell?

Status
Not open for further replies.

Klopper

MIS
Dec 7, 2000
84
US
If I have this code in an Excel VBA module:

Function MyFunc
MyFunc = (Range("A1").value) + 10
End function

And I enter in to any cell, lets say B2, in the spreadsheet:

=MyFunc()

I get returned in cell B2 the value in cell A1 plus 10. Which is good!
But, how can I programmatically recalculate the value in B2 when the value in A1 has changed? ie what is the code to refresh / recalculate the cells that use custom built functions?

TIA
Klopper
 
Hi,
You need to have a dynamic target range rather than a static range...
Code:
Function MyFunc(rng)
    MyFunc = (rng) + 10
End Function
Skip,
metzgsk@voughtaircraft.com
 
...actually, to be rigerously correct, the syntax should be:
Code:
Function MyFunc(rng As Excel.Range)
    MyFunc = (rng) + 10
End Function
Skip,
metzgsk@voughtaircraft.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top