top of page
Writer's pictureDerek Burrows-Johnson

Excel Macros with ChatGPT



The new AI tool is a powerful tool and can help produce macros in your Excel tables to automating data entry or data cleaning tasks, creating macros for complex calculations and automating the generation of results.






First go to https://openai.com/blog/chatgpt/ and create an account. Then go to https://chat.openai.com/chat to start asking it to generate processes to integrate into your Excel tables.


Keep in mind that the quality of the generated code can vary depending on the specific use case and the context that ChatGPT is given. It would be important to thoroughly test and debug any macros generated by ChatGPT before using them in a production environment.


EXAMPLES

  1. SUMMARIZING data with the range A1:D10. If the table was larger, the range could be extended past D10 to E12, G20, F25 etc.

Sub SummarizeData() '

Select the data range that you want to summarize

Range("A1:D10").Select'Insert subtotals at each change in the "Column A" field Selection.Subtotal GroupBy:=1, Function:=xlSum, TotalList:=Array(2, 3, 4), _ Replace:=True, PageBreaks:=False, SummaryBelowData:=True

EndSub




2. VISUALIZING data can be done using promts in ChatGPT. This macro creates a bar chart in the active worksheet, based on the data in the range A1:B10, with a title "Bar Chart"


Sub CreateBarChart()

'Define the data range for the chart

Dim dataRange As Range

Set dataRange = Range("A1:B10") 'Create the chart

Dim chartObject As ChartObject

Set chartObject = ActiveSheet.ChartObjects.Add _

(Left:=150, Width:=600, Top:=50, Height:=400)

'Set the chart type to Bar

chartObject.Chart.ChartType = xlBarClustered

'Set the data range for the chart

chartObject.Chart.SetSourceData Source:=dataRange

'Add a title to the chart

chartObject.Chart.HasTitle = True

chartObject.Chart.ChartTitle.Text = "Bar Chart"

EndSub






These are just two examples and barely scratch the surface of the benefits of integrating these two pieces of software. ChatGPT is a powerful language model that when integrated with Excel, can automate many tasks, such as data analysis, visualization, and report generation, making it an extremely valuable tool for businesses and organizations of all sizes. With ChatGPT and Excel, you can save time and reduce errors, allowing you to focus on more important tasks.



Cheers,


The Table Originals team




Comments


bottom of page