How to Use AI to Code [6-Step Framework]
Read 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: