How to create Excel macros with ChatGPT

0
0
How to create Excel macros with ChatGPT

The advent of artificial intelligence has been a breath of fresh air for many office tasks that used to take us a long time. The other day we saw how we can create a PowerPoint presentation using AI, and today we will follow the same dynamic to create Excel macros.

All this without having to write formulas or be an expert in Microsoft Excel. In our case we will use ChatGPT, but we can use any AI that can be programmed, such as Windows Copilot, Bing Chat, Google Bard or other similar text generative AIs.

How to create a macro in Excel using ChatGPT

For this example we will create a simple macro with ChatGPT. The idea is to understand the concept and then be able to develop it in more complex data tables.

Suppose we have an Excel sheet where we have a list of superheroes, each with a corresponding name, power level and group to which it belongs.

Next, we’ll create a macro that tells us who the strongest superhero is.

  • Open the browser and enter the ChatGPT website.
  • Ask the AI ​​to create a macro that meets your needs. For this you can use the following template:
    • Write an Excel VBA macro for (target). The data starts from line (X) to line (Y) (counting the headers) in the following order:
    • (Paste your headings)
    • The name of the page is (Name)
  • Be sure to specify the page where the table is located. If the data is on the second sheet, it will clearly indicate that it is “Sheet2”.
  • Once ChatGPT has generated the code, click “Copy the code” to copy it to the clipboard.
Read Also:  We know about 1% of the chemical substances in the Universe

Now that we have the macro code, we go to the Microsoft Excel program.

  • And Excel, Press the ALT+F11 keys to open the Visual Basic editor.
  • In the top menu, click “Insert -> Module”.
  • Paste the code you generated with ChatGPT and press the ” keyCONTROL+S” to save the macro. You will see a warning message: accept it by clicking “Yes”
  • Close the Visual Basic window and return to the Excel sheet where you have the table with the data.
  • Press the keys ALT+F8select the macro you compiled in Visual Basic and click “implemented”.

The application we created using the macro will run automatically. In our case, we asked the macro to tell us who is the strongest superhero on the table, that’s exactly what it did, showing us the following message on the screen:

Read Also:  Pirelli P Zero Trofeo RS: The sportiest tire ever

How to create Excel charts with ChatGPT

We can also use macros to perform other types of tasks in Excel, such as create charts from the data in the table. The process to follow is the same: we will create a macro with chart data, we will compile it in Visual Basic and then we will execute it in Excel.

  • Ask ChatGPT to create a macro to generate an Excel chart. You can use the following prompt as a template:
    • Write an Excel VBA macro to create a chart: the X axis shows (HEADER A) and the Y axis shows (HEADER B). The data starts from line (X) to line (Y) (counting the headers) in the following order:
    • (Paste your headings)
    • The name of the page is (Name).

Following the same example as before, we ask ChatGPT to create a graph that breaks down the power levels of all the superheroes found in our data table.

Once we have the code, we go to Excel and press ALT + F11 keys. Inside Visual Basic we click on the “Insert -> Module” and paste the code we just generated in ChatGPT. We press the keys at the same time CONTROL+S to save the macro and close Visual Basic.

Read Also:  Whatsapp: find out what happens if you click on the application icon on iOS and Android

Finally, we go to the Excel sheet where the data is located and press the keys ALT+F8, we select the macro to create the graph and click “Run”. Excel will automatically create the graph with the data we pass to it.

Excel has several types of charts available, so we can ask ChatGPT to create column and bar charts, hierarchy charts, waterfall charts, line charts, pie charts, donut chart, etc.

Finally, remember that ChatGPT is not perfect, and sometimes its code contains compilation errors. If so, don’t hesitate to tell the AI ​​what error you got and ask it to correct it. ChatGPT will polish the code and in a few seconds it will return a new macro with the error resolved.

Now that you know how to create Excel macros with ChatGPT, it’s all about starting to practice with your own data tables. It will undoubtedly help you save a lot of time and effort.