From the course: Python in Excel: Data Outputs in Custom Data Visualizations and Algorithms

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Using the XL Excel function and Python variables

Using the XL Excel function and Python variables

- [Instructor] If we want to use Excel objects like worksheet cells within our Python in Excel code blocks, we can use the Excel function within the Python function PY to reference these input parameters. Within our Python code in Excel, we can set variables in the same way we would for Python code run in another IDE. In our first line of code, let's set A = 1. In the second line of code we'll create a new Python variable X and set it equal to A + 1. The output as expected, returns two here. We can also use the Python code variables in other Excel cells. In the third row of our results table where it says X squared, we'll again use the Python function where we'll reference the X variable. Notice, we see it appear from the dropdown menu as we type in the variable name, we can then choose Tab to select it and we'll confirm these results. Now let's square the output. We'll use the double asterisk followed by two, and we'll hit Ctrl + Enter again to update our formula. As we expect, this…

Contents