Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9269641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:10:32+00:00 2026-06-18T15:10:32+00:00

I am developing an excel add in with my following code . I created

  • 0

I am developing an excel add in with my following code .
I created a Class library and added the following code

using System;
using System.Collections.Generic;
 using System.Linq;
 using System.Text;
  using System.Runtime.InteropServices;
  using Microsoft.Win32;

  namespace MyCustomAutomation
  {

// Replace the Guid below with your own guid that

// you generate using Create GUID from the Tools menu

[Guid("5268ABE2-9B09-439d-BE97-2EA60E103EF6")]
[ClassInterface(ClassInterfaceType.AutoDual)]
[ComVisible(true)]
public class MyFunctions
{
    public MyFunctions()
    {

    }

    public double MultiplyNTimes(double number1, double number2, double timesToMultiply)
    {
        double result = number1;
        for (double i = 0; i < timesToMultiply; i++)
        {
            result = result * number2;
        }

        return result;


    }


    [ComRegisterFunctionAttribute]
    public static void RegisterFunction(Type type)
    {

        Registry.ClassesRoot.CreateSubKey(

          GetSubKeyName(type, "Programmable"));

        RegistryKey key = Registry.ClassesRoot.OpenSubKey(

          GetSubKeyName(type, "InprocServer32"), true);

        key.SetValue("",

          System.Environment.SystemDirectory + @"\mscoree.dll",

          RegistryValueKind.String);
    }

    [ComUnregisterFunctionAttribute]
    public static void UnregisterFunction(Type type)
    {

        Registry.ClassesRoot.DeleteSubKey(

          GetSubKeyName(type, "Programmable"), false);
    }

    private static string GetSubKeyName(Type type,

      string subKeyName)
    {

        System.Text.StringBuilder s =

          new System.Text.StringBuilder();

        s.Append(@"CLSID\{");

        s.Append(type.GUID.ToString().ToUpper());

        s.Append(@"}\");

        s.Append(subKeyName);

        return s.ToString();

    }
   }
  }

I installed it and the Function works fine in excel .I am able to use MultiplyNTimes function that returns the value.However my issue is that when i call the function from the cell the result is displayed in the same cell itself whereas I want the result to be played in any cell other than the called cell.I am totally clueless as I cannot reach any direction.
Please help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T15:10:33+00:00Added an answer on June 18, 2026 at 3:10 pm

    To have the result in another cell, simply return the result as an array. So as an example for another version of your MultiplyNTimes function, this can be written as:

     public double[] MultiplyNTimesNextCell(double number1, double number2, double timesToMultiply)
    {
           // result[0] is the value returned on the first cell
           // result[1] is the value returned on the next cell
           double[] result = new double[] {0, number1};
           for (double i = 0; i < timesToMultiply; i++)
           {
                // hardcoded to result[1] where to return the result
                result[1] = result[1] * number2;
           }
    
            return result;
    }
    

    And then when you use this function in Excel, you must use the array formula syntax, which means if you enter the function in A1, then select both cells A1 and B1, then press F2 and then Ctrl+Shift+Enter

    Also note, I have simply used 0 to be returned in the cell where the formula is entered. If you wish to change this to another value of different types, you can use an array of object as the result data type.

    So for example, you can rewrite it in this way:

    public object[] MultiplyNTimesObj(double number1, double number2, double timesToMultiply)
    {
         object[] result = new object[] { "MultiplyNTimesObj=", number1 };
         for (double i = 0; i < timesToMultiply; i++)
         {
             result[1] = (double)result[1] * number2;
         }
    
         return result;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing a User defined function in Excel using C# and Class library
Using C# I am developing an Excel add-in. This add-in opens a Windows Form
I am developing a C# add in for Excel (using VSTO tools). I have
I am currently developing an Excel add-in in C#, and I am using interop
I'm developing an Excel VSTO Document Level Add-In using Composite Application Guidance (Prism for
I am developing an add-in for Microsoft Excel, using Visual Studio .NET 2008. The
I'm developing an Excel 2007 add-in using Visual Studio Tools for Office (2008). I
We are developing C# winform application.We are using OpenXMLSDK for accessing and modifying Excel
I am developing an excel add-in. I have serial numbers(ex. 100 psc) and I
I am developing a Excel shared Add-in which has the menu called Custom which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.