Excel How To Understand VBA Macros with ChatGPT

Whether you’re trying to decipher a macro created by someone else in your organization, or you’re trying to make sure a code sample you found online is safe to run, ChatGPT can help you understand the VBA code. If you’re not a programmer, understanding macro VBA code can be a daunting task. In this post, we’ll learn how to get ChatGPT to explain existing VBA code making it easier to understand what the macro does.


Step-by-step guide

ChatGPT is a web-based tool that can help you understand VBA macro code. Let’s explore how ChatGPT can help you understand VBA code with a couple of examples.

Exericse 1

Let’s say you have inherited an Excel workbook with a “Run Macro” button, but you aren’t exactly sure what the macro does. All you see is this:

One option would be to just click the button and see what happens. But, if you’d rather see the underlying code before you run it, you can open the Visual Basic Editor (Alt + F11). When you do, you see the following code:

If you haven’t really explored VBA code, it may not be clear what the code does. If the original developers were still available, we could contact them. If they aren’t, one option would be to ask ChatGPT.

We open a new chat at the free chat.openai.com website. We start our prompt with something like “explain the following excel vba code: ” and then paste the code from the editor. ChatGPT responds with:

You’ll notice that ChatGPT breaks down the code line by line and explains what each line does and how they all work together to achieve the desired result. Wow!

Exercise 2

ChatGPT can also help you understand code samples from the internet. If you find a code sample online and you’re unsure if it’s safe to run, you can paste it into ChatGPT and ask if it’s safe.

For example, you find a website that includes the following code sample:

You aren’t sure what it does exactly, so you’d like to understand it before running it in your Excel. So, you start a new chat with something like “explain the following vba code, and let me know if it is safe to run: ” and paste in the code. ChatGPT responds:

As you can see, ChatGPT provides a detailed analysis of the code and discusses the safety of running the code. It even suggests that you create a backup of your workbook before running the code. Wow!


ChatGPT can be a great help when you’re trying to understand VBA code. It can provide detailed explanations of the code, and can even help you determine if a code sample is safe to run. So if you ever find yourself in a situation where you need to understand macro code, give ChatGPT a try.

If I can provide any additional information, or you have any other ChatGPT suggestions, please share by posting a comment below … thanks!

Sample file

Posted in ,

Jeff Lenning

I love sharing the things I've learned about Excel, and I built Excel University to help me do that. My motto is: Learn Excel. Work Faster.

Excel is not what it used to be.

You need the Excel Proficiency Roadmap now. Includes 6 steps for a successful journey, 3 things to avoid, and weekly Excel tips.

Want to learn Excel?

Our training programs start at $29 and will help you learn Excel quickly.

Leave a Comment