How to Use AI to Code [6-Step Framework]
Apr 26, 2024Read time - 5 mins
If you're wanting to take your skills to the next level, and automate using code, this newsletter is for you.
Before ChatGPT I’d never thought seriously about writing code (although I’d dabbled).
I’d muddled along with ‘the way I’d always done things’ as I didn’t have the time to learn new skills.
Fast forward to after Generative AI became a thing. I’ve managed to do some amazing things with code, that I previously thought would be impossible for a non-developer like me.
And the good news is, you don’t have to be a techie to use code to your advantage.
Even simple, low risk code, can lead to some pretty big time savings.
All you need is a framework…
Coding in Finance
Coding comes in many forms.
If could be:
- A VBA Macro
- An Office Script
- Full blown Python Code
Technically, an Excel Formula is a little line of code, which makes you a developer already! ๐
Where it gets complicated, is each coding language is different.
Cue AI.
Because AI is trained on MASSIVE amounts of data, it works as an excellent copilot when using a range of coding languages.
BUT, asking AI to “write me some code to do [thing]” probably won’t produce the results you want.
So here’s a framework that’ll help you use AI to successfully code.
Ready?
The Framework
1. Define
Whether you’re writing code, implementing systems, or deploying software, you won’t get far if you don’t have a clear definition of the results you want to produce.
This doesn’t need to be war and peace.
It could be as simple as “This is the way we do things now [enter process and data points]. This is the way we want to do things [enter desired process and data points]”.
The reason mapping this out is so useful, as it creates context for AI to be able to do it’s work.
Plus, having your process documented is good practise.
IMPORTANT - Don’t bite off more than you can chew. To begin with, I’d recommend choosing a simple process (e.g a data manipulation task) rather than a complicated multi-step process. Start with baby steps.
2. Language
In my last newsletter on creating scalable automations in Excel, we touched on languages. The examples being VBA or Office Scripts depending on your use case.
Within this framework, the coding languages available to you will be broader, so selecting the right one is a crucial step.
From experience, VBA and Python offer the lowest barrier to entry.
VBA being the choice of preference for many finance pros that can’t get access to Python on their machines.
Prompt:
“Here’s a solution design for a process I want to automate using code [copy solution design as text, or upload document]. Which coding languages can I use to achieve this as a non-developer? Don’t generate any code yet, just give me a high-level step by step of how this would be achieved with each language”
3. Test Environment
For this stage we need to act as a developer.
A developer will work in a 'Sandbox' before the deploy their code to a 'Live' environment.
Now we don't need a load of complicated virtual environments to achieve this.
But it's a good idea to have some file folders on your machine ring-fenced to save your code, as well as any data files you're using.
4. Build
Now comes the fun bit. Building out our code!
We’ll start by combining our work from steps 1 & 2 into a prompt that will set the context for the AI.
Prompt 1:
“Here’s the solution definition for a process that I want to automate using code [enter definition]. I want to use [enter coding language] to achieve this. Before you generate any code, please confirm you understand what I’m looking to achieve”
Hopefully it’ll respond favourably
Prompt 2:
“OK, start writing the code. Please clearly explain each element of the code as you write it so that I have complete understanding of the way that it works”
PRO Tip - Code in chunks. Remember earlier when I said it’s better to start with baby steps? Pick one part of your process and start there. Then move onto the next… then the next…
5. Troubleshoot
It’s unlikely your code will be perfect first time around.
If you get errors, just paste them into your AI chat with a simple message like “I’m receiving this error [paste error] help me resolve it”, and it’ll help you troubleshoot.
PRO Tip - Save versions of your code. This way, you can keep track of your progress as you make modifications, and you can roll back to a previous version if you end up creating a mess.
6. Deploy
Once the code has been run successfully in your test folder, you can then start using it ‘live’.
IMPORTANT - I’m a big fan of using code to automate non-critical personal tasks (e.g manipulating Excel) but deploying code without experience on mission critical tasks is high risk. Seek develop help for anything high risk that will affect your business process.
Anyway, assuming you’ve been testing on a small subset of your data, you can now run with your full data.
And you can always be doubly safe by making copies of you data to run your code before you go live live…
Putting it Into Practise
In this example, we’ll be chunking up multi-entity sales data into separate spreadsheets.
- Download the example Solution Definition and dummy data from this folder
- Follow me creating VBA code on this video
- You can cheat by copying the code from the folder too ;)
You’ll be coding with AI in no time.
Until next time.
Adam
---
2 Ways I can help
When you're ready here's how I can help you:
Subscribe to Framework Friday
1 tech, productivity, or mental framework to your inbox most Fridays. Access to my tech toolkit, 76 tools and how I've used them โ Many of them free. Links to all my 100s of LinkedIn posts โ Updated weekly
Subscribe for free withย just your e-mail:
I respect your privacy. Opt-out any time.