How to set cell to ExcelError.ExcelErrorNA

Feb 11, 2013 at 7:48 PM
How can I set a cell to ExcelError.ExcelErrorNA?

Excel.Range xlCurrentCell = xlApp.ActiveCell;
xlCurrentcell.Value = ExcelError.ExcelErrorNA;

...willl put the number 42 into that cell.

/Niels
Coordinator
Feb 11, 2013 at 8:24 PM
Edited Feb 11, 2013 at 8:24 PM
Hi Niels,

From this post: http://groups.google.com/group/exceldna/browse_frm/thread/67a9a6c49e0b49b3
        public static object ToComError(ExcelError excelError)
        {
            int code;
            switch (excelError)
            {
                case ExcelError.ExcelErrorNull:
                    code = -2146826288;
                    break;
                case ExcelError.ExcelErrorDiv0:
                    code = -2146826281;
                    break;
                case ExcelError.ExcelErrorRef:
                    code = -2146826265;
                    break;
                case ExcelError.ExcelErrorName:
                    code = -2146826259;
                    break;
                case ExcelError.ExcelErrorNum:
                    code = -2146826252;
                    break;
                case ExcelError.ExcelErrorNA:
                    code = -2146826246;
                    break;
                case ExcelError.ExcelErrorGettingData:
                case ExcelError.ExcelErrorValue:
                default:
                    code = -2146826273;
                    break;
            }
            return new System.Runtime.InteropServices.ErrorWrapper(code);
        }
-Govert
Feb 12, 2013 at 2:24 PM
Thanks Govert!