When developing Mathematica code, it is best to separate input and output definitions from the main analysis portion of the routine. This way your analysis code can be easily adapted to obtain inputs and send outputs anywhere.
Here is a sequence of Mathematica commands that performs some analysis.
This section defines inputs.
This section performs your analysis.
This section displays outputs.
To use this code as an Excel macro, you only need to load the ExcelLink package to modify the input and output sections. Before doing this, open Excel and type in the same inputs into the workbook locations indicated in the following.
This section loads required packages.
This section defines inputs from Excel.
This section returns outputs to Excel.
In this example, the input and output range is the same. This is a way of performing in-place evaluation.
To convert an existing Mathematica notebook to be used as an Excel macro:
For more information, see Code Box Deployment.