Table of Contents
Generative AI is so powerful that it can write content for you on any given topic, process large amount of data, summarize paragraphs and even it can generate code for any programming language. You just need to provide the Prompt to ChatGPT and ChatGPT will do rest of the things.
Here, we will try to explore the programming capabilities of ChatGPT and develop a Data Entry Application using different. prompts.
You can watch step-by-step tutorial on YouTube to learn how can we create a data entry application using ChatGPT in MS Excel and VBA.
Below are the Prompts which we have utilized in our tutorial. Feel free to use, modify and share it for further uses.
Prompt – 1
‘I will be presenting a series of prompts that are interconnected and pertain to the VBA development in MS Excel. Are you prepared to proceed with this sequence of prompts?’
Prompt – 2
‘As an experienced VBA Developer for Microsoft Excel, please generate VBA code to create a UserForm named ‘frmUserForm’ in Excel.
Ensure that all controls in the UserForm are correctly aligned, sized, and labeled, providing a professional appearance. Please set the UserForm’s properties as follows:
Caption: “Data Entry Form”
The UserForm should contain the following fields and controls, each with its own label, aligned and spaced appropriately for data entry:
Employee Name: Consisting of a Label and a TextBox control.
Gender: Consisting of a Label and Option Buttons for Male & Female.
Mobile Number: Consisting of a Label and a TextBox control.
Country Name: Consisting of a Label and a ComboBox control, initially empty.
Address: Consisting of a Label and a TextBox control, capable of displaying 5 lines of text.
Additionally, please add two CommandButtons with the following properties:
Submit: Control Type: CommandButton
Reset: Control Type: CommandButton
Submit and Rest buttons must be aligned at the bottom of the screen and horizontally aligned to each other.
Please assign coding friendly names to all controls for easy reference in other code. Lastly, don’t forget to set the name of the UserForm as ‘frmUserForm’.’
Prompt – 3
‘In continuous to previous code, write a new VBA sub procedure named ‘Initialize’. It will set all the fields of existing user form ‘frmUserForm’ to blank values and populate the Country Combo Box with the following options: India, Pakistan, Germany, France, Japan, China, and Philippines. You can write the Code using With and End with block referring frmUserForm directly as frmUserForm is already available.’
Prompt – 4
‘In additiona to previous code, write a VBA sub procedure that will be executed when the Submit button is clicked on the UserForm ‘frmUserForm’. This procedure will transfer the data entered in the UserForm to the next available blank row in the Database sheet of this workbook.
The corresponding fields in the Database sheet starting from Column A to Column H and the Data Entry Form are as follows. Also, First row in the Database sheet has column headers.
S. No. – Generate a unique serial number for each record.
Name – Employee name entered in the text box
Gender – Value selected from the Male or Female option buttons
Mobile Number – Mobile number entered in the text box
Country Name – Value selected from the ComboBox
Address – Address entered in the text box
Submitted By – Username of the application
Submitted on – Current date and time
Before transferring the data to the Database sheet, a confirmation message with Yes/No options will be displayed to the user. If the user selects Yes, the data will be transferred to the Database sheet. If the user selects No, nothing will happen. Once the data is successfully transferred, a confirmation message will be displayed indicating that the data has been transferred to the Database sheet. Additionally, the Initialize sub procedure will be called to reset all the controls on the UserForm.’
Prompt – 5
‘In continuous to the previous code, write a new VBA sub procedure on the click event of the Reset Command Button in UserForm ‘frmUserForm’. This code will prompt the users with a confirmation message asking whether they want to reset the form or not. The confirmation message will have Yes and No buttons. If the user clicks on Yes, the code will call the Initialize procedure to reset the form and show the confirmation message that form is reset now. If the user clicks on No, the code will do nothing.’
Download Excel File
Disclaimer: This tutorial is designed for educational purposes only and is meant to demonstrate the capabilities of ChatGPT. The code generated by ChatGPT is based on the provided prompts and may vary in accuracy and effectiveness. It’s essential to thoroughly review and validate any code generated by ChatGPT before using it in your projects. Always exercise caution and consult official documentation and expert resources for best practices in programming. Let’s proceed with the tutorial, keeping in mind the limitations and considerations of using AI-generated code.