Hi Roman,
Excel does not have a way for a UDF to abandon the calculation, and not return a value.
Your UDF can read the old value of the cell, but that would not be an appropriate result to return if your function is used in a compound formula (e.g. =MYFUNC()+1).
You might cache your function results yourself, and then return the value that you have cached if the ‘skip’ switch is on.
-Govert
--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
exceldna+u...@googlegroups.com.
To post to this group, send email to exce...@googlegroups.com.
Visit this group at https://groups.google.com/group/exceldna.
For more options, visit https://groups.google.com/d/optout.
You can get the current values (not text) from the cell calling your UDF.
But how does that help you?
Consider this function:
[ExcelFunction(IsMacroType=true)]
public static object GetNewValueIfGreaterThanCurrentValue(double newValue)
{
var caller = XlCall.Excel(XlCall.xlfCaller) as ExcelReference;
if (caller == null)
return newValue;
var currentValue = (double)caller.GetValue();
if (newValue > currentValue)
return newValue;
return currentValue;
}
Try this by putting “5” into cell A1, and the formula = GetNewValueIfGreaterThanCurrentValue(A1) into cell B1.
Then change the values in cell A2 to by higher or lower…
But this breaks if you have a compound formula, since the relationship between the function return and the cell value is not fixed – there can be a compound formula.
Why is caching the results not an option?
return caller != null ? caller.GetValue() : DefaultValue;
}
(Keep in mind, that IsTheradSave now is no longer supported, as Govert explained in a different thread)
Roman
Am Donnerstag, 30. März 2017 14:19:32 UTC+2 schrieb FastExcel:
if (!mi.IsMacroType && mi.IsThreadSafe && XlAddIn.XlCallVersion >= 12)
functionType += "$";
if (mi.IsMacroType)
functionType += "#";
IsInFormulaEditMode()
if the editor is open.