My first experience programming with ChatGPT and Visual Basic | Xyclos
Updated: Sep 19
Introduction
I had a very special and interesting request from a customer.
Marcela, a service salesperson for an international company, keeps an Excel workbook in which she records her prospects' quotes on each page.
Currently, the book has just 10 pages or quotes, but she anticipates that it will be difficult to navigate through the pages when it has more quotes.
The Challenge
What Marcela needs is an index of all the sheets in the workbook, where she can search by the client's name (recorded in the label of each sheet) and have Excel automatically open that sheet so she can work on the client's quote.
Initial Solution
As a first option, I suggested using the "Activate" window that appears when you right-click on the sheet forward and back icons.
This workaround would allow you to view and select the sheet in the workbook you need to work on.
Looking for a Better Solution with ChatGPT
First attempt
I prompted ChatGPT, giving general instructions.
ChatGPT immediately generated Visual Basic code with implementation instructions.
I copied the code into a new module in my client's Excel workbook.
When running the macro, I got an error.
Refining the Code
I shared the bug with ChatGPT and asked them to review it.
ChatGPT generated new code that worked better, but was still not perfect.
The Importance of Specificity
I opened a new chat and provided much more detailed instructions.
ChatGPT generated three subroutines:
One to generate the index
Another one to search when there was a change in the sheet
A code to update the number of sheets and the index of the entire book
Bottom line
I managed to create a solution that:
Create the index with the names of all the sheets in the book
Allows you to search the index by name
Automatically opens the selected customer's quote page
If a new Sheet or Quote is created, refresh everything by clicking on the index sheet to perform a new search
Reflections
The most significant thing, and I told her this, is that Marcela has taken the initiative to seek an improvement in repetitive processes. That is the attitude.
The process took about two hours to get everything debugged and working properly.
The most challenging thing was to establish precise and detailed instructions for ChatGPT.
I managed to program 100% with ChatGPT without writing code manually. I could have done it with Copilot , Claude or Gemini which also generate code. Speaking of this, I also generated a presentation using VBA and Gemini which you can see on Google Gemini: Create a PowerPoint presentation
Prior knowledge of Excel and its environment was crucial to the success of the project.
Conclusion
The confluence of three elements was key: human knowledge , Excel and Artificial Intelligence.
This experience demonstrates the importance of thoroughly preparing yourself in Excel and developing confidence to work with an AI like ChatGPT.
Invitation to Prepare
I invite you to prepare by taking our Excel, Power Query and Power BI courses:
With this preparation, you will also be able to create your own solutions with Excel and the very important contribution and collaboration that artificial intelligence provides us.
#ChatGPTCoding #ExcelAutomation #VBAMacros #AIprogramming #MicrosoftExcel #BusinessProductivity #ArtificialIntelligence #ContinuousLearning #AssistedProgramming #TechSolutions #DataManagement #BusinessEfficiency #CodingWithAI #ExcelTips #PowerQueryExcel #PowerBI #PersonalDevelopment #BusinessTechnology #OfficeAutomation #TechnologyInnovation
Comments