{"id":2332,"date":"2024-09-29T18:05:34","date_gmt":"2024-09-29T18:05:34","guid":{"rendered":"https:\/\/haimagazine.com\/?p=2332"},"modified":"2025-06-26T15:03:44","modified_gmt":"2025-06-26T13:03:44","slug":"automation-with-ai-part-1-creating-vba-scripts-with-chatgpt","status":"publish","type":"post","link":"https:\/\/haimagazine.com\/en\/ai-how-to\/automation-with-ai-part-1-creating-vba-scripts-with-chatgpt\/","title":{"rendered":"Automation with AI (Part 1) | Creating VBA Scripts with ChatGPT"},"content":{"rendered":"<p class=\"has-text-align-center\"><\/p><p>Will ChatGPT replace accountants? No, but it can make their lives easier, especially in areas that previously required really good relations with the IT department.<\/p><p>Technology is advancing at an incredible pace, and with it, the amount of data in our organizations is growing. What else has significantly increased in recent years? The number of new obligations resulting from regulatory changes. The effect? Piles of additional, often tedious and repetitive work, and massive amount of data to process. I will show you examples of how we can perform these routine and tedious processes more efficiently by automating them appropriately. This way, we can dedicate more time to more interesting tasks that bring value and satisfaction. This is here generative artificial intelligence comes to our aid, so that using only natural language (and therefore no programming) we can, among other things, create effective macros or find inspiration for improvements in other processes.<\/p><p><\/p><p><strong>APPLICATION OF AI IN ACCOUNTING<\/strong><\/p><p>Let&#8217;s take a look at how the capabilities of <strong><mark style=\"background-color:#82D65E\" class=\"has-inline-color\">ChatGPT<\/mark><\/strong> can be utilized in the field of accounting and taxes. Let\u2019s break down the data workflow in these areas into four sections:<\/p><ol start=\"1\" class=\"wp-block-list\"><li><strong>Data Collection<\/strong><\/li><\/ol><p>With ChatGPT, we can create intuitive and clear templates for collecting high-quality data more quickly. For example, data can be gathered through forms, questionnaires, or readable and easy-to-fill tables.<\/p><ol start=\"2\" class=\"wp-block-list\"><li><strong>Data Cleaning<\/strong><\/li><\/ol><p>In this step, AI-generated scripts can help remove duplicates, fill in missing information, standardize formats, and remove special characters that are not accepted by our systems in subsequent stages.<\/p><ol start=\"3\" class=\"wp-block-list\"><li><strong>Data Processing<\/strong><\/li><\/ol><p>After collecting and cleaning the data, AI-generated scripts can assist us in merging data, creating financial reports, or adjusting files to the structure required by our financial accounting system.<\/p><ol start=\"4\" class=\"wp-block-list\"><li><strong>Verification<\/strong><\/li><\/ol><p>The increasing complexity of regulations means that more and more transactions require more detailed analyses. AI-generated scripts can assist accountants by automatically checking for threshold exceedances or compliance with specified conditions. With the help of scripts, we can receive a list of transactions that require further in-depth analysis.<\/p><p><strong>Practical Example \u2013 Convenient Data Merging<\/strong><strong><\/strong><\/p><p>Let&#8217;s demonstrate with a simple example how we can use ChatGPT to create a script in Visual Basic for Applications (VBA) that merges data from multiple files. The task is as follows: <strong><mark style=\"background-color:#82D65E\" class=\"has-inline-color\">combine data from dozens of files and tables into one file<\/mark><\/strong>. We have 24 files, 48 tables, and thousands of rows. Let&#8217;s work with ChatGPT to create a VBA script that will merge this data with a single click.<\/p><p><strong>1. Defining Needs and Assumptions<\/strong><\/p><p>Let&#8217;s start by analyzing the process we want to automate and define our objectives. Describe this as precisely as possible.<\/p><ul class=\"wp-block-list\"><li>Combine multiple files saved in xlsx format, each containing 2 tabs with data, into one consolidated file for further analysis.<\/li>\n\n<li>The structure of the input files is consistent \u2013 they contain 2 tabs with 10-column tables. The table headers are in the first row.<\/li><\/ul><figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\"><figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"759\" height=\"256\" data-id=\"2363\" src=\"https:\/\/haimagazine.com\/wp-content\/uploads\/2024\/06\/1.1-2.jpg\" alt=\"\" class=\"wp-image-2363\" srcset=\"https:\/\/haimagazine.com\/wp-content\/uploads\/2024\/06\/1.1-2.jpg 759w, https:\/\/haimagazine.com\/wp-content\/uploads\/2024\/06\/1.1-2-300x101.jpg 300w, https:\/\/haimagazine.com\/wp-content\/uploads\/2024\/06\/1.1-2-600x202.jpg 600w\" sizes=\"auto, (max-width: 759px) 100vw, 759px\" \/><figcaption class=\"wp-element-caption\">1. Input file structure<\/figcaption><\/figure><\/figure><ul class=\"wp-block-list\"><li>Use the tools already included in the Microsoft 365.<\/li>\n\n<li>The files to be merged are located in the directory [C:\\Examples\\1\\Input].<\/li>\n\n<li>The number and names of files change<\/li>\n\n<li>The tab names in the files do not change: &#8220;VAT naliczony&#8221; (Input VAT) and &#8220;VAT nale\u017cny&#8221; (Output VAT).<\/li>\n\n<li>Data merging will be performed periodically on a varying number of files.<\/li><\/ul><p>To increase the chances of receiving a fully functional script on the first response, it&#8217;s important to remember a few key things. First and foremost, <mark style=\"background-color:#82D65E\" class=\"has-inline-color\"><strong>precisely define the assumptions, input data structure, and expected output format.<\/strong><\/mark><\/p><p><strong>2. Creating the Prompt<\/strong><\/p><blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>Based on the collected information, we create a prompt, which is a query to ChatGPT. Clarify in the prompt that during table merging, we want the header names not to be duplicated and for the program to ask the user where to save the generated file. Remember that general and ambiguous terms can lead to less precise responses and decrease the chance of obtaining a satisfactory result.<\/p><\/blockquote><p>Here is the prompt along with the model&#8217;s response:<\/p><p><mark style=\"background-color:#B7B7B7\" class=\"has-inline-color\">&nbsp; <\/mark><\/p><p><\/p><p><\/p><p><\/p><div class=\"wp-block-group has-global-padding is-layout-constrained wp-block-group-is-layout-constrained\"><div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\"><div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:100%\"><figure class=\"wp-block-table is-style-stripes\"><table><tbody><tr><td><em><mark style=\"background-color:#F3F3F3\" class=\"has-inline-color\"><strong>MODEL RESPONSE<\/strong><br><br>To merge multiple XLSX files into a single summary file using VBA in Microsoft 365, we need to create a macro that meets the stated objectives. Below is the detailed VBA code that accomplishes this goal:<br><br>1. Open Excel and go to the VBA editor (Alt + F11).<br>2. Navigate to ThisWorkbook (double-click on &#8220;ThisWorkbook&#8221; in &#8220;VBAProject&#8221;). <br>3. Paste the following code into ThisWorkbook<br><br><br>Sub MergeFiles()<br>&nbsp;&nbsp;&nbsp; Dim FolderPath As String<br>&nbsp;&nbsp;&nbsp; Dim outputWorkbook As Workbook<br>&nbsp;&nbsp;&nbsp; Dim inputWorkbook As Workbook<br>&nbsp;&nbsp;&nbsp; Dim outputSheet1 As Worksheet<br>&nbsp;&nbsp;&nbsp; Dim outputSheet2 As Worksheet<br>&nbsp;&nbsp;&nbsp; Dim inputSheet1 As Worksheet<br>&nbsp;&nbsp;&nbsp; Dim inputSheet2 As Worksheet<br>&nbsp;&nbsp;&nbsp; Dim FileName As String<br>&nbsp;&nbsp;&nbsp; Dim LastRow As Long<br>&nbsp;&nbsp;&nbsp; Dim lastRowOut1 As Long<br>&nbsp;&nbsp;&nbsp; Dim lastRowOut2 As Long<br>&nbsp;&nbsp;&nbsp; Dim okresVAT As String<br>&nbsp;&nbsp;&nbsp; Dim SavePath As String<br>&nbsp;&nbsp;&nbsp; Dim i As Integer<br>&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp; &#8216; Path to folder with input files<br>&nbsp;&nbsp;&nbsp; FolderPath = &#8220;C:\\Przyk\u0142ady\\1\\Input\\&#8221;<br>&nbsp;&nbsp;<br>&nbsp;&nbsp; &nbsp; &#8216; Create a new output workbook<br>&nbsp;&nbsp;&nbsp; Set outputWorkbook = Workbooks.Add<br>&nbsp;&nbsp;&nbsp; Set outputSheet1 = outputWorkbook.Sheets(1)<br>&nbsp;&nbsp;&nbsp; outputSheet1.Name = &#8220;VAT naliczony&#8221;<br>&nbsp;&nbsp;&nbsp; Set outputSheet2 = outputWorkbook.Sheets.Add(After:=outputWorkbook.Sheets(1))<br>&nbsp;&nbsp;&nbsp; outputSheet2.Name = &#8220;VAT nale\u017cny&#8221;<br>&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp; &#8216; Downloading a list of files in a folder<br>&nbsp;&nbsp;&nbsp; FileName = Dir(FolderPath &amp; &#8220;*.xlsx&#8221;)<br>&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp; &#8216; Initialization of header column flag<br>&nbsp;&nbsp;&nbsp; Dim headerSet As Boolean<br>&nbsp;&nbsp;&nbsp; headerSet = False<br>&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp; &#8216; Processing of each file<br>&nbsp;&nbsp;&nbsp; Do While FileName &lt;&gt; &#8220;&#8221;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set inputWorkbook = Workbooks.Open(FolderPath &amp; FileName)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8216; Downloading bookmarks from the input file<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set inputSheet1 = inputWorkbook.Sheets(&#8220;VAT naliczony&#8221;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set inputSheet2 = inputWorkbook.Sheets(&#8220;VAT nale\u017cny&#8221;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8216; Set headers in the output file (if not already set)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Not headerSet Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For i = 1 To 10<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; outputSheet1.Cells(1, i).Value = inputSheet1.Cells(1, i).Value<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; outputSheet2.Cells(1, i).Value = inputSheet2.Cells(1, i).Value<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next i<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; outputSheet1.Cells(1, 11).Value = &#8220;Okres VAT&#8221;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; outputSheet2.Cells(1, 11).Value = &#8220;Okres VAT&#8221;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; headerSet = True<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8216; Copying data from the tab &#8220;VAT naliczony&#8221;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LastRow = inputSheet1.Cells(inputSheet1.Rows.Count, 1).End(xlUp).Row<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lastRowOut1 = outputSheet1.Cells(outputSheet1.Rows.Count, 1).End(xlUp).Row + 1<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; inputSheet1.Range(&#8220;A2:J&#8221; &amp; LastRow).Copy Destination:=outputSheet1.Range(&#8220;A&#8221; &amp; lastRowOut1)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; outputSheet1.Range(&#8220;K&#8221; &amp; lastRowOut1 &amp; &#8220;:K&#8221; &amp; lastRowOut1 + LastRow &#8211; 2).Value = FileName<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8216; Copying data from the tab &#8220;VAT nale\u017cny&#8221;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LastRow = inputSheet2.Cells(inputSheet2.Rows.Count, 1).End(xlUp).Row<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lastRowOut2 = outputSheet2.Cells(outputSheet2.Rows.Count, 1).End(xlUp).Row + 1<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; inputSheet2.Range(&#8220;A2:J&#8221; &amp; LastRow).Copy Destination:=outputSheet2.Range(&#8220;A&#8221; &amp; lastRowOut2)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; outputSheet2.Range(&#8220;K&#8221; &amp; lastRowOut2 &amp; &#8220;:K&#8221; &amp; lastRowOut2 + LastRow &#8211; 2).Value = FileName<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; inputWorkbook.Close SaveChanges:=False<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FileName = Dir<br>&nbsp;&nbsp;&nbsp; Loop<br>&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp; &#8216; Question to the user about where to save the resulting file<br>&nbsp;&nbsp;&nbsp; With Application.FileDialog(msoFileDialogSaveAs)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .Title = &#8220;Zapisz plik wynikowy&#8221;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .FilterIndex = 1<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If .Show = -1 Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SavePath = .SelectedItems(1)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; outputWorkbook.SaveAs FileName:=SavePath<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br>&nbsp;&nbsp;&nbsp; End With<br>&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp; outputWorkbook.Close SaveChanges:=True<br>&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp; MsgBox &#8220;The file was saved as &#8221; &amp; SavePath<br>&nbsp;<br>End Sub<br><br><br><br><strong>Explanation: <br>Variable declaration:<\/strong> We declare variables needed to store paths, file names, workbooks and worksheets. &nbsp; <br><strong>Retrieving the path and name of the output file:<\/strong> The user is asked for the location and name of the output file. &nbsp; <br><strong>Creating a new output file:<\/strong> A new workbook is created with two sheets &#8220;VAT naliczony&#8221; and &#8220;VAT nale\u017cny&#8221;. &nbsp; <strong>P<\/strong><br><strong>rocessing files in a folder:<\/strong> The loop goes through all the XLSX files in the folder, opening them and copying the corresponding data to the output file. &nbsp; <br><strong>Copying headers:<\/strong> Column headers are copied only once, from the first input file. &nbsp; <br><strong>Copying data:<\/strong> Data is copied to the corresponding sheets in the output file, and the name of the source file is added to the eleventh column.<br><strong>Closes the files and saves the output file: <\/strong>The output file is saved to the location you selected. &nbsp; <br><br>Make sure you have the proper permissions to read and write files to the specified locations and that all files are as intended (i.e., have the correct sheets and headers).<\/mark><\/em><\/td><\/tr><\/tbody><\/table><\/figure><\/div><\/div><\/div><p><strong>3. Verification<\/strong><\/p><p>Before entering your first code into an Excel workbook, you must first add a Developer tab to the Ribbon. To do this, you need to:<\/p><ol start=\"1\" class=\"wp-block-list\"><li>On the File tab, go to Options and Ribbon Customization.<\/li>\n\n<li>In the Customizing Ribbon and Home tabs area, select the Developer checkbox.<\/li><\/ol><figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-2 is-layout-flex wp-block-gallery-is-layout-flex\"><figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"869\" data-id=\"2370\" src=\"https:\/\/haimagazine.com\/wp-content\/uploads\/2024\/06\/1.2-1024x869.jpg\" alt=\"\" class=\"wp-image-2370\" srcset=\"https:\/\/haimagazine.com\/wp-content\/uploads\/2024\/06\/1.2-1024x869.jpg 1024w, https:\/\/haimagazine.com\/wp-content\/uploads\/2024\/06\/1.2-300x255.jpg 300w, https:\/\/haimagazine.com\/wp-content\/uploads\/2024\/06\/1.2-768x652.jpg 768w, https:\/\/haimagazine.com\/wp-content\/uploads\/2024\/06\/1.2-600x509.jpg 600w, https:\/\/haimagazine.com\/wp-content\/uploads\/2024\/06\/1.2.jpg 1217w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">2. How to turn on developer mode<\/figcaption><\/figure><\/figure><p>After activating the developer&#8217;s tab, just use the Alt + F11 keyboard shortcut to open the VBA editor. Enter the code in the main editor window.<\/p><figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-3 is-layout-flex wp-block-gallery-is-layout-flex\"><figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"567\" data-id=\"2388\" src=\"https:\/\/haimagazine.com\/wp-content\/uploads\/2024\/06\/1.33-1024x567.jpg\" alt=\"\" class=\"wp-image-2388\" srcset=\"https:\/\/haimagazine.com\/wp-content\/uploads\/2024\/06\/1.33-1024x567.jpg 1024w, https:\/\/haimagazine.com\/wp-content\/uploads\/2024\/06\/1.33-300x166.jpg 300w, https:\/\/haimagazine.com\/wp-content\/uploads\/2024\/06\/1.33-768x426.jpg 768w, https:\/\/haimagazine.com\/wp-content\/uploads\/2024\/06\/1.33-600x332.jpg 600w, https:\/\/haimagazine.com\/wp-content\/uploads\/2024\/06\/1.33.jpg 1054w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">3. VBA Editor View<\/figcaption><\/figure><\/figure><p>After entering the code, we can close the VBA editor. To run the macro you should:<\/p><ol start=\"1\" class=\"wp-block-list\"><li>Select Developer Tab.<\/li>\n\n<li>Click the Macros button<\/li>\n\n<li>Select the appropriate macro name and click the run button.<\/li><\/ol><figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-4 is-layout-flex wp-block-gallery-is-layout-flex\"><figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"708\" height=\"158\" data-id=\"2382\" src=\"https:\/\/haimagazine.com\/wp-content\/uploads\/2024\/06\/1.4-1.jpg\" alt=\"\" class=\"wp-image-2382\" srcset=\"https:\/\/haimagazine.com\/wp-content\/uploads\/2024\/06\/1.4-1.jpg 708w, https:\/\/haimagazine.com\/wp-content\/uploads\/2024\/06\/1.4-1-300x67.jpg 300w, https:\/\/haimagazine.com\/wp-content\/uploads\/2024\/06\/1.4-1-600x134.jpg 600w\" sizes=\"auto, (max-width: 708px) 100vw, 708px\" \/><figcaption class=\"wp-element-caption\">4. How to run a macro<\/figcaption><\/figure><\/figure><p><\/p><p>After running the macro and specifying the location to save the file, I received the following message:<\/p><figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-5 is-layout-flex wp-block-gallery-is-layout-flex\"><figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"365\" height=\"158\" data-id=\"2385\" src=\"https:\/\/haimagazine.com\/wp-content\/uploads\/2024\/06\/1.5.jpg\" alt=\"\" class=\"wp-image-2385\" srcset=\"https:\/\/haimagazine.com\/wp-content\/uploads\/2024\/06\/1.5.jpg 365w, https:\/\/haimagazine.com\/wp-content\/uploads\/2024\/06\/1.5-300x130.jpg 300w\" sizes=\"auto, (max-width: 365px) 100vw, 365px\" \/><figcaption class=\"wp-element-caption\">5. Confirmation of saving the final file <\/figcaption><\/figure><\/figure><p>Let&#8217;s look at what our output file looks like:<\/p><figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-6 is-layout-flex wp-block-gallery-is-layout-flex\"><figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"869\" height=\"364\" data-id=\"2395\" src=\"https:\/\/haimagazine.com\/wp-content\/uploads\/2024\/06\/1.55-1.jpg\" alt=\"\" class=\"wp-image-2395\" srcset=\"https:\/\/haimagazine.com\/wp-content\/uploads\/2024\/06\/1.55-1.jpg 869w, https:\/\/haimagazine.com\/wp-content\/uploads\/2024\/06\/1.55-1-300x126.jpg 300w, https:\/\/haimagazine.com\/wp-content\/uploads\/2024\/06\/1.55-1-768x322.jpg 768w, https:\/\/haimagazine.com\/wp-content\/uploads\/2024\/06\/1.55-1-600x251.jpg 600w\" sizes=\"auto, (max-width: 869px) 100vw, 869px\" \/><figcaption class=\"wp-element-caption\">6. Output file structure<\/figcaption><\/figure><\/figure><p>The macro worked as expected and did not require any changes to the code, although this is not always the case. Sometimes the code generated by ChatGPT may be faulty and not work. In such cases, you should describe the error and ask the model to fix it. Usually, after a maximum of a few iterations, the error is located and corrected.<\/p><p>We obtained an output file with combined data in two tabs related to VAT Incurred and VAT Due, with an additional column [VAT Period]. Providing detailed descriptions of our requirements and assumptions in the prompt, including information about paths, tab names, and file structure, allowed us to obtain a working macro.<\/p><p><strong>4. Adding more functionalities<\/strong><\/p><p>After merging the files, we can add further elements to automate the process. For example, ChatGPT can create a script that generates a file with a list of transactions that meet the criteria we set. Let&#8217;s discuss this using the example of transactions subject to the split payment mechanism. VAT taxpayers are required to apply this mechanism if:<\/p><ol start=\"1\" class=\"wp-block-list\"><li>They sell or purchase &#8220;sensitive&#8221; goods or services, which are listed in Annex 15 to the VAT Act, and simultaneously,<\/li>\n\n<li>The total invoice amount, i.e., the gross value of the entire invoice, exceeds 15 000 PLN.<\/li><\/ol><p>The split payment mechanism must be applied if even one item on the invoice, whose total gross value exceeds 15 000 PLN, concerns sensitive goods or services.<\/p><pre class=\"wp-block-code\"><code>To get a list of transactions that meet the above conditions, we could define in the prompt when a given transaction should be included. Looking at the file structure, we could specify that we want to receive items that meet the following conditions for individual rows:<\/code><\/pre><ol start=\"1\" class=\"wp-block-list\"><li>In column G, the value equals 1 (The transaction is marked with GTU code 02, which covers sensitive goods).<\/li>\n\n<li>The sum of the values of items in columns from I to J is greater than 15 000 PLN.<\/li><\/ol><p>We can apply a similar approach to creating scripts that verify and search for items that meet other conditions specified by us.<\/p><p><strong>SUMMARY<\/strong><\/p><p>If you are just starting your adventure with creating macros, it is worth starting with simple examples and gradually moving on to more complex tasks. Maybe you want the macro to create a new file with selected tabs and contain values instead of formulas? Or do you need a macro that copies data from one file to another? Or maybe you want to automatically create a PDF file and save it in a specified location? The potential of generative artificial intelligence in accounting is enormous. Its incredible advantage is that we can get solutions perfectly tailored to our needs. And all of this by having a conversation in natural language, as if we were asking a more experienced colleague to perform a task, not an AI model. Something that was rather the domain of science fiction movies not long ago is now within our reach.<\/p>","protected":false},"excerpt":{"rendered":"<p>See how AI can be used to create macros in Excel and save valuable time.<\/p>\n","protected":false},"author":16,"featured_media":2152,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"rank_math_lock_modified_date":false,"footnotes":""},"categories":[791],"tags":[],"popular":[],"difficulty-level":[38],"ppma_author":[357],"class_list":["post-2332","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ai-how-to","difficulty-level-medium"],"acf":[],"authors":[{"term_id":357,"user_id":16,"is_guest":0,"slug":"mpezowicz","display_name":"Marcin Pezowicz","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/39181f1c2712633923d1f9b67408c9f6459e89a5fd7106887cc359b52cf8a433?s=96&d=mm&r=g","first_name":"Marcin","last_name":"Pezowicz","user_url":"","job_title":"","description":"BPO Consultant. Z wykszta\u0142cenia ksi\u0119gowy oraz automatyk i robotyk. Specjalizuje si\u0119 w usprawnianiu proces\u00f3w z obszaru ksi\u0119gowo\u015bci i podatk\u00f3w."}],"_links":{"self":[{"href":"https:\/\/haimagazine.com\/en\/wp-json\/wp\/v2\/posts\/2332","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/haimagazine.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/haimagazine.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/haimagazine.com\/en\/wp-json\/wp\/v2\/users\/16"}],"replies":[{"embeddable":true,"href":"https:\/\/haimagazine.com\/en\/wp-json\/wp\/v2\/comments?post=2332"}],"version-history":[{"count":34,"href":"https:\/\/haimagazine.com\/en\/wp-json\/wp\/v2\/posts\/2332\/revisions"}],"predecessor-version":[{"id":5194,"href":"https:\/\/haimagazine.com\/en\/wp-json\/wp\/v2\/posts\/2332\/revisions\/5194"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/haimagazine.com\/en\/wp-json\/wp\/v2\/media\/2152"}],"wp:attachment":[{"href":"https:\/\/haimagazine.com\/en\/wp-json\/wp\/v2\/media?parent=2332"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/haimagazine.com\/en\/wp-json\/wp\/v2\/categories?post=2332"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/haimagazine.com\/en\/wp-json\/wp\/v2\/tags?post=2332"},{"taxonomy":"popular","embeddable":true,"href":"https:\/\/haimagazine.com\/en\/wp-json\/wp\/v2\/popular?post=2332"},{"taxonomy":"difficulty-level","embeddable":true,"href":"https:\/\/haimagazine.com\/en\/wp-json\/wp\/v2\/difficulty-level?post=2332"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/haimagazine.com\/en\/wp-json\/wp\/v2\/ppma_author?post=2332"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}