Read our blogs, tips and tutorials
Try our exercises or test your skills
Watch our tutorial videos or shorts
Take a self-paced course
Read our recent newsletters
License our courseware
Book expert consultancy
Buy our publications
Get help in using our site
431 attributed reviews in the last 3 years
Refreshingly small course sizes
Outstandingly good courseware
Whizzy online classrooms
Wise Owl trainers only (no freelancers)
Almost no cancellations
We have genuine integrity
We invoice after training
Review 30+ years of Wise Owl
View our top 100 clients
Search our website
We also send out useful tips in a monthly email newsletter ...
|
Calling Python code from within Excel, and the vast functionality it unlocks Part five of a five-part series of blogs |
|---|
|
Excel and Python are getting ever more intertwined: you can now use the PY function to write (and call) Python code from within an Excel worksheet
|
The secret to good programming is to encapsulate logic in functions - like this one to add two numbers together (obviously this logic already exists in Excel, but I'm using it to illustrate the principle):
def add_numbers_in_python(
first_number:int,
second_number:int
):
# add the two numbers
return first_number + second_number
A good way to incorporate these within Excel is to add them to the first worksheet in a workbook, and if necessary hide this:

We get the function to return an empty string. Normally you would not display the title in B1 or shading in B2!
You can then reference this elsewhere in your workbook:

Here we're using the function we defined on the first worksheet to add two numbers together.
Suddenly I can see vast vistas of possibility opening up!
| Parts of this blog |
|---|
|
Some other pages relevant to the above blogs include:
Kingsmoor House
Railway Street
GLOSSOP
SK13 2AA
Landmark Offices
99 Bishopsgate
LONDON
EC2M 3XD
Holiday Inn
25 Aytoun Street
MANCHESTER
M1 3AE
© Wise Owl Business Solutions Ltd 2025. All Rights Reserved.