Advanced Excel Automation, VBA Macro Development, and Artificial Intelligence Systems

Fundamentals and Categorization of Automation

Automation is defined as the application of technology tools, robotics, and processes to achieve predefined outcomes with minimal human input. It encompasses several stages and domains of life, offering businesses advantages such as cost and time savings, optimization, consistency, improved customer satisfaction, higher regulatory compliance, and more effective resource allocation. By automating routine processes, human resources can be shifted toward higher-level strategic and objective tasks.

There are several distinct categories of automation across the technological landscape. Industrial or fixed automation involves custom-built, purposefully designed machines in big plants executing repetitive tasks at high scale, such as vehicle assembly plants. Programmable automation is a more advanced form where dedicated machines can be reconfigured by human input to address different builds or design tasks. Robotic Process Automation (RPA) utilizes software programs called bots to mimic human behaviors, such as mouse clicks or filling out digital forms on websites. These bots are often used for routine digital tasks like invoice processing or issuance. Business Process Automation (BPA), also known as workflow automation, involves creating single, continuous digital processes for entire sequences of events, such as the cycle from customer order placement to fulfillment. Finally, smart or intelligent automation incorporates Artificial Intelligence (AI), generative AI, and machine learning to manage highly complex processes and workflows.

Excel Macro Development and Troubleshooting

Excel automation often starts with the macro recorder, which translates user actions into code. For instance, the task of sorting a dataset can be automated by creating a macro named sort dataset and assigning it to a shortcut key such as CTRL+SHIFT+SCTRL+SHIFT+S. Sorting a dataset typically involves selecting the entire range and applying multiple levels of criteria: date (chronological, oldest to newest), product (alphabetical, AA to ZZ), grade (AA to CC, where AA is the best and CC is the worst), and units (numerical, largest to smallest).

Macros record actions in a programming language called Visual Basic for Applications (VBA). The Visual Basic Editor (VBE) can be accessed via the developer tab or by pressing ALT+F11ALT+F11. Within the editor, code is organized into modules. A macro always begins with the word SubSub, followed by the macro name and empty parentheses ()( ), and terminates with the command EndSubEnd Sub. Lines of code preceded by an apostrophe appear in green and are known as comments. These lines are ignored by the compiler (the component responsible for executing code) and serve only as notes for the user to understand the code’s logic. Logic identifies objects (like ranges) and applies methods (verbs like select or sort).

When a macro is recorded on a specific worksheet, such as one titled January, the code may explicitly reference that sheet (Worksheets("January")Worksheets("January")). This prevents the macro from functioning correctly on other sheets, like February. To make the macro dynamic, the hard-coded sheet name must be replaced with the term ActiveSheetActiveSheet. Furthermore, recorded macros often hard-code the range of the dataset based on the number of rows present during recording (e.g., A2:A91A2:A91). If subsequent datasets have more rows, the macro will ignore the data beyond the original row limit. A common work-around is to manually edit the code to include a larger buffer, such as changing row 9191 to 10,00010,000.

Computational Thinking and Pattern Recognition

Computational thinking is the process of breaking a single large problem into smaller, manageable sub-problems and tackling them one by one. This skill is indispensable for developing robust automation solutions that can adapt to varying datasets. Before recording a macro, it is essential to map the process and identify common denominators or fixed points of reference across different data sets.

Data consistency is a primary principle of automation. One must determine if various data sheets, such as monthly bank statements, share consistent layouts, column structures, and formatting. If layouts vary, the data may need to be standardized before automation can proceed. Identifying fixed anchors, such as data always starting on row 1818, allows the use of relative referencing to select data regardless of the total number of entries.

In complex tasks, such as updating an expense dashboard from intermittent bank statements, temporary placeholder cells can be used for intermediate calculations. For example, to identify new spending categories, one might use a COUNTIF()COUNTIF( ) or VLOOKUP()VLOOKUP( ) function in a temporary column to check if a category from a new statement already exists in the master list. Once new data is identified and processed, these temporary calculations can be cleared to maintain an aesthetically appealing and uncluttered spreadsheet.

Artificial Intelligence in Programmable Environments

Generative AI and Large Language Models (LLMs) such as ChatGPT, Claude, and Google Gemini represent forms of weak or narrow AI. These systems are designed to perform specific tasks, such as language processing, text analysis, image generation, and code creation. Unlike theoretical General AI or Super AI, narrow AI cannot switch between vastly different domains, such as driving a car and operating a factory, but they are highly effective at assisting with VBA coding.

When using AI to write code, provide specific context and detail. Users can prompt an AI to edit existing VBA code to make it more efficient, such as adding a loop that allows a macro to run across all sheets in a workbook with a single button click. It is recommended to use permanent chats rather than temporary ones for projects requiring an audit trail, as temporary chats do not save history and are not used for training the model by companies like OpenAI. Many LLMs allow for the sharing of conversation links, which can be useful for collaboration or assessment verification.

Platforms like ChatGPT and Claude are currently neck-and-neck in benchmark performance. While ChatGPT is noted for its versatility in generating video and images through simple prompts, Claude is often preferred for certain text and code analysis tasks. Both are examples of Deep Neural Networks that have become powerful tools for automating more complex digital processes through an iterative process of refinement and troubleshooting.

VAT Act Compliance and Invoice Validation

Kenobi Enterprises, a registered VAT vendor, must ensure that all supplier invoices meet the requirements of the VAT Act to claim input VAT refunds. An input VAT claim is a reimbursement from SARS for the VAT portion paid to suppliers as part of a purchase price. A macro can be devised to automate the validation of these invoices through specific criteria.

To be deemed a valid tax invoice for Kenobi Enterprises, the document must meet three primary criteria: the invoice must be in the name of Kenobi Enterprises, the supplier must be a registered VAT vendor, and the invoice must contain the VAT registration numbers for both the supplier and the customer (Kenobi). A standard VAT registration number typically consists of 1010 digits and begins with the number 44.

Invoices from different suppliers, such as Baxter, Peterson and Sons (Blue Office Solutions) or CapCircuit, often have varying layouts. Baxter, Peterson and Sons may provide a breakdown including quantity, unit price excluding VAT, subtotal VAT, and total inclusive of VAT. CapCircuit might only list the amount excluding VAT before calculating the total. A sophisticated macro must identify common denominators (anchors) across these varied formats to extract relevant data, validate the mandatory fields, and populate a summary table with the details of only those invoices found to be legally valid.