UDF for Dynamic Array To Fetch Formulas

44 views
Skip to first unread message

xlFAQ

unread,
Sep 6, 2022, 2:21:41 PM9/6/22
to Excel-DNA
Hi friends,

Being a newbie in this regard, in context of the said subject please see if any of you experts can suggest the correct way to assign a correct value instead of the highlighted portion, to be assigned in the following piece of C# Code to return the Formula of returning a formula possessed by a cell / range:

        public static object XLformulas(object[,] input)
        {
            var rows = input.GetLength(0);
            var cols = input.GetLength(1);

            var result = new object[rows, cols];
            for (int fRow = 0; fRow < rows; fRow++)
            {
                for (int fCol = 0; fCol < cols; fCol++)
                {
                    result[fRow, fCol] = ????
                }
            }
            return result;
        }

Thanks in advance

Kedar Kulkarni

unread,
Sep 14, 2022, 4:36:35 PM9/14/22
to Excel-DNA
Hi there,

There is a formula called =FORMULATEXT(G11:G15) that can give you the formula.. 

However, if you still want to reinvent the wheel :)  following is the method.

The challenge is that this need a cell reference and we must convert the parameter to a valid cell reference. Now it comes with its own side effects. Please have a look at following link and convert the excel reference to cell reference and then use cell.Formula at ???? to get the actual formula.

this should be straight forward once you have excel references. though I will recommend using FormulaText formula.

thanks,
Reply all
Reply to author
Forward
0 new messages