Home » excel » excel – Function Return Value Not Updating

excel – Function Return Value Not Updating

Posted by: admin May 14, 2020 Leave a comment


I have an Excel workbook with multiple sheets and I am trying to run a test function to return a cell value that gets updated based on values from a different sheet.
Here is my basic function which simply returns a value from an array:

Function test(t2)
    Dim costArray As Variant
    costArray = Array(Range("W34"), Range("W35"), Range("W36"))
    test = costArray(1)
End Function

This properly returns the correct value, but when I update a dependency cell value from the different sheet, the return value gets set to 0 and I have to manually refresh the function to get the updated value. As you can see, I have tried to use the Application.Volatile method, but does not seem to help.

Any thoughts?

How to&Answers:

Try like this:

Public Function TestMe(ParamArray costArray() As Variant) As Variant
    TestMe = costArray(1)
End Function

I guess that the Application.Volatile concerns only the parameters. Thus, give the three parameters as a range.

The ParamArray specifies that a procedure parameter takes an optional array of elements of the specified type. ParamArray can be used only on the last parameter of a parameter list.