Excel VBA Macros - Beginner to PRO Masterclass with Code Samples

Excel VBA Macros - Beginner to PRO Masterclass with Code Samples

Introduction and Technical Difficulties

The speaker apologizes for the late start due to technical difficulties. They ask if the audience can hear them clearly and request feedback in the chat.

  • The speaker apologizes for the late start and mentions technical difficulties.
  • Asks the audience to confirm if they can hear them clearly.
  • Requests feedback in the chat regarding their location and previous VBA experience.

Audience Engagement

The speaker acknowledges audience responses and engagement.

  • Acknowledges that the audience can hear them.
  • Mentions some locations of viewers and asks about their VBA experience.
  • Shares poll results indicating that a majority of viewers have not done any VBA coding this year.

Audience Interaction

The speaker continues to engage with the audience, mentioning specific locations of viewers.

  • Mentions a busy chat room before the stream started.
  • Shares viewer locations from India, London, Canada, Nigeria, Singapore, Gambia, UK, Sweden, etc.
  • Shares a personal story about being in Sweden 14 years ago during this time of year.

Speaker's Experience with VBA

The speaker discusses their experience with VBA coding.

  • Describes themselves as an occasional developer when it comes to VBA.
  • Mentions having knowledge of programming but considers themselves more of a hobby coder when it comes to VBA.

Refreshments and Audience Drinks

The speaker asks viewers what they are drinking while sharing their own coffee choice.

  • Asks viewers what they are drinking.
  • Mentions grabbing a cup of coffee before starting the stream.

Viewer Responses on Drinks

The speaker acknowledges viewer responses regarding their drinks.

  • Acknowledges viewers' drink choices, including hazelnut coffee, water, tap water, green tea, etc.
  • Wishes viewers enjoyment with their drinks.

Agenda for the Live Stream

The speaker outlines the three main topics they plan to cover during the live stream.

  • Outlines three main topics for the live stream:
  1. Quick introduction to VBA.
  1. Creating a practical scenario using VBA.
  1. Possible advanced glimpses of VBA depending on time constraints.

New Section

In this section, the speaker introduces the idea of building a simple to-do list application using Excel. They mention that it will be a straightforward project that even those unfamiliar with VBA can follow along.

Building a Simple To-Do List Application

  • The speaker suggests building a simple to-do list application using Excel.
  • They assure that even if one is not familiar with VBA, they can use other features in Excel to achieve the same result.
  • The goal is to create something simple and easy to understand without getting lost in too many details.

New Section

Before diving into the actual VBA coding, the speaker provides some announcements and guidelines for viewers during the live stream.

Announcements and Guidelines

  • Viewers are encouraged to use the chat for discussions and questions while the speaker explains concepts.
  • When asking a question, prefix it with "q" so that it stands out among other messages.
  • It is important not to spam messages or repeat them multiple times.
  • If someone knows a better way of doing something being explained, they should share their comment or message so others can benefit from it as well.
  • The speaker mentions that although they have experience with VBA coding, they are using it less frequently due to advancements in technology and enhanced Excel features.

New Section

The speaker addresses some questions from viewers regarding accessing the video later, timing of live streams, and feedback on their plan.

Addressing Viewer Questions

  • A viewer asks if the video will be available for later viewing. The speaker confirms that usually live streams are not always available afterwards but encourages checking back tomorrow if needed.
  • The timing of live streams is chosen on weekends to accommodate viewers who may have more time then compared to weekdays.
  • A viewer named Tom expresses agreement with the speaker's plan.

New Section

The speaker discusses specific questions about VBA coding and mentions upcoming topics to be covered during the stream.

Questions and Upcoming Topics

  • The speaker acknowledges specific questions about VBA coding and assures that they will be addressed as the stream progresses.
  • They mention that this introductory phase is like the opening scenes of a movie, building up to the main content.
  • The speaker outlines their plan for the stream, including hanging around at the end to answer questions and share their views.
  • They also mention discussing how VBA compares to other programming options in Excel, as well as their personal usage of VBA in current times.

New Section

The speaker demonstrates a simple VBA application they created for promoting their live stream.

Demonstration of a Simple VBA Application

  • The speaker shows a one-page VBA application they created to promote their live stream.
  • It consists of a button labeled "Click me" which, when clicked, displays a message box saying "Don't forget VBA live stream tomorrow" along with another button labeled "See you soon."
  • This demonstration showcases a basic example of what can be achieved with VBA in Excel.

Setting Up Excel for VBA Programming

In this section, the speaker discusses the initial setup required to start programming with VBA in Excel.

Enabling Developer Ribbon

  • To use VBA frequently, it is recommended to enable the Developer ribbon in Excel.
  • Right-click anywhere on the ribbon and select "Customize the Ribbon."
  • Check the "Developer" option and click OK to add the Developer ribbon.

Introduction to VBA

  • VBA (Visual Basic for Applications) is a programming interface built into Microsoft Excel and other Office software.
  • It allows users to automate tasks, connect different Office applications, and enhance Excel's capabilities.
  • VBA is derived from the programming language called BASIC.

History of VBA in Excel

  • VBA has been available in Excel since at least version 2003.
  • It provided a programmable interface that allowed users to customize and extend Excel's functionalities.
  • With VBA, there are no limits on what can be achieved with Excel, such as connecting to databases or building complex applications.

Enhanced Capabilities of Modern Excel

  • Over time, Excel itself has evolved and gained more built-in capabilities.
  • Some tasks that previously required VBA can now be accomplished directly within Excel.
  • However, using VBA still offers additional flexibility and customization options.

Understanding VBA as a Programming Language

This section provides an overview of what VBA is as a programming language and its relationship with BASIC.

What is VBA?

  • VBA stands for Visual Basic for Applications.
  • It is a programming language integrated into Microsoft Office applications like Excel, Outlook, PowerPoint, and Word.

Relationship with BASIC

  • The name "Visual Basic for Applications" indicates that it is derived from BASIC (Beginner's All-purpose Symbolic Instruction Code).
  • BASIC is a general-purpose programming language used to instruct computers on performing specific tasks.
  • VBA extends the capabilities of BASIC and provides a backend tool for customizing Office applications.

Practical Applications of VBA

  • VBA can be used not only in Excel but also in other Office applications like Outlook, PowerPoint, and Word.
  • It allows users to automate tasks, connect different applications, and create powerful workflows.
  • For example, VBA code in Excel can extract data and compose an email in Outlook based on that data.

Evolution of Excel with VBA

This section highlights the evolution of Excel's capabilities with the introduction of VBA.

Early Adoption of VBA

  • The speaker personally started using VBA since at least Excel 2003.
  • Prior to the introduction of VBA, Excel had limitations in terms of customization and automation.

Expanding Possibilities with VBA

  • With the addition of VBA as a programmable interface, users could enhance Excel's capabilities beyond its built-in features.
  • Users began building complex applications that connected to databases or performed advanced calculations using VBA.

Modern Excel Features

  • In recent years, Excel has significantly expanded its built-in capabilities.
  • Some tasks that previously required VBA can now be accomplished directly within Excel without coding.

Continued Relevance of VBA

  • Despite the advancements in built-in features, using VBA still offers additional flexibility and customization options.
  • Many professionals continue to leverage the power of VBA to create sophisticated solutions within Excel.

The transcript provided does not cover any further sections.

Using CONCATENATE function in older versions of Excel

In older versions of Excel, there was no built-in function to easily combine text values. The only available function was CONCATENATE, which required manually specifying each value to be combined. This process was cumbersome and time-consuming, especially when dealing with a large number of values.

  • The SUM function can be used to combine numeric values.
  • The CONCATENATE function is used for combining text values.
  • Concatenating multiple text values using CONCATENATE requires manually specifying each value.

Introduction to the CONCAT and TEXTJOIN functions in modern Excel

Modern versions of Excel have introduced new functions that simplify the process of combining text values. The CONCAT function and the TEXTJOIN function provide easier ways to concatenate multiple text values.

  • The CONCAT function can combine multiple text values without the need for manual specification.
  • The TEXTJOIN function allows concatenation with a specified delimiter.
  • These new functions reduce the need for using VBA macros for simple concatenation tasks.

Recording macros in VBA

VBA (Visual Basic for Applications) provides a way to automate tasks in Excel by recording macros. Macros are pieces of VBA code that can listen to user actions and repeat them when executed again.

  • The Developer ribbon in Excel contains a record macro button for recording macros.
  • Macros can be named and customized.
  • Macros can be recorded by performing actions on a blank sheet.
  • Macros are useful for automating repetitive tasks.

Example of automating cell coloring using VBA

An example is given where a repetitive task of coloring a specific cell is automated using VBA macros.

  • The example involves filling the color of a selected cell.
  • The macro records the action of selecting the cell and filling it with color.
  • The recording can be stopped from either the Developer ribbon or the status bar.

Conclusion

The use of VBA macros in Excel allows for automation of repetitive tasks, reducing manual effort and increasing efficiency.

  • VBA macros provide a way to automate tasks in Excel.
  • Recording macros can simplify the process of creating VBA code.
  • Macros are particularly useful for automating repetitive actions.

Using Macros in Excel VBA

In this section, the speaker explains how to use macros in Excel VBA to automate repetitive tasks.

Building and Running a Macro

  • To build a macro, record the desired actions using the macro recorder.
  • Once the macro is built, it can be run by selecting it from the developer tab or using Visual Basic editor.
  • Running the macro will repeat the recorded actions without needing to manually perform them again.

Viewing and Editing Macros

  • To view and edit macros, go to the developer tab and select "Macros".
  • Alternatively, open Visual Basic editor by clicking on "Visual Basic" in the developer ribbon.
  • The code for the macro can be found under modules in the current workbook module.

Understanding VBA Code

  • The code for a macro starts with sub followed by a name and ends with end sub.
  • Comments can be added using single quotes (') and are ignored by VBA.
  • The first step in a macro may involve selecting a specific cell or range using range.select.
  • Actions like filling color are recorded as multiple steps but can be simplified to one line of code.
  • Colors are based on Excel's color theme rather than RGB values unless specified otherwise.

New Section

The color theme in Excel can affect the colors of various elements. Changing the color theme can result in different colors being applied to cells and other objects.

Color Theme Changes

  • When changing the color theme in Excel, all elements that had the second color in the previous theme will have their colors changed to match the new theme. This includes cells, shapes, and other objects.
  • To maintain consistency, it is recommended to switch back to a default or desired color theme after making changes.

Adding Code for Custom Actions

  • Instead of recording a macro for repetitive tasks like filling a cell with a specific color and adding text, you can write code to automate these actions.
  • To add the value "awesome" to cell B3, you can use either of these two methods:
  • range("B3").value = "awesome"
  • selection.value = "awesome"
  • The second method assumes that B3 is already selected before running the code.

Triggering Macros with Buttons

  • Clicking on macros in the developer tab every time can be inconvenient. You can create buttons that trigger macros for easier access.
  • Insert a shape or icon into your worksheet and assign a macro to it by right-clicking and selecting "Assign Macro."
  • Buttons can also be added to the ribbon for easy access across multiple sheets.

Saving Files with Macros

  • When saving files with VBA code, choose a format that enables macros such as .xlsm.
  • Opening xlsm files may prompt a warning about macros, which is normal.

The transcript is in English, so the notes are also provided in English.

Adding Macros to Ribbon

In this section, the speaker explains how to add macros to the ribbon in Excel.

Adding Macros to Ribbon

  • Open the ribbon customization menu by right-clicking on the ribbon and selecting "Customize the Ribbon".
  • Choose "Macros" from the "Popular Commands" section.
  • Locate and select the desired macro, such as "Fill Color".
  • Pre-select an area of the ribbon where you want to add the macro.
  • If necessary, create a new group for organizing macros.
  • Rename the group if desired and customize its icon.
  • Click OK to add the macro button to the ribbon.

Creating a Group for Macros

This section focuses on creating a group for macros in Excel's ribbon.

Creating a Group for Macros

  • Click on "New Group" in order to create a new group within the ribbon.
  • Rename the group as needed, such as "My Macros".
  • Add the desired macro, like "Fill Color", into this newly created group.
  • Customize further by renaming or changing its icon if desired.

Accessing Macro Button in Ribbon

Here, it is explained how to access and use a macro button added to Excel's ribbon.

Accessing Macro Button in Ribbon

  • After adding a macro button to the ribbon, it will be available wherever you are working in Excel.
  • Simply click on that button (e.g., Fill Color) whenever you want to execute that specific macro function.

Limitations of Macro Availability

The limitations of using macros added through this method are discussed here.

Limitations of Macro Availability

  • Macros added through this method are specific to the current file and may not be available in other files.
  • If another file with the same macro is open, it can locate and execute the macro.
  • However, if the original file containing the macro is closed, accessing the macro may result in a warning message or require enabling macros.

Personal Macro Workbook for Consistent Availability

The speaker suggests using a personal macro workbook for consistent availability of macros across all files.

Personal Macro Workbook for Consistent Availability

  • Setting up a personal macro workbook allows any macros created to be consistently available across all Excel files.
  • Instructions on how to set up a personal macro workbook can be found by searching online or visiting the speaker's website.
  • This ensures that macros are accessible regardless of which file is open.

Creating a Simple To-Do Application Using Macros

In this section, the speaker introduces creating a simple to-do application using macros.

Creating a Simple To-Do Application Using Macros

  • The speaker demonstrates how to create a basic to-do application using VBA macros in Excel.
  • This application utilizes the techniques explained earlier to add functionality and automate tasks within Excel.

Timestamps beyond this point do not have associated content related to Excel or VBA.

Using Chat GPT and VBA for Automation

The speaker discusses the possibility of using Chat GPT and VBA together for automation purposes. They mention that if there is sufficient interest, they can create a video explaining how to use this combination effectively.

Exploring the Potential of Chat GPT and VBA

  • The speaker expresses their willingness to create a video tutorial on using Chat GPT and VBA together if there is enough interest from viewers.
  • They explain that personally, they don't use this combination extensively because they have a good understanding of VBA and find it more efficient to start coding right away.
  • However, they are open to exploring the potential of using Chat GPT for other tasks if viewers express interest through comments or other means.

Changing Column Width in Excel

The speaker introduces the topic of changing column width in Excel and suggests taking it up as a challenge in the next exercise. They plan to incorporate this feature into their to-do list application.

Challenge: Changing Column Width

  • The speaker mentions that changing column width can be an interesting challenge to tackle.
  • They propose incorporating this feature into their existing to-do list application.
  • This challenge will involve writing code to modify column widths dynamically based on user requirements.

Understanding Pivot Tables in VBA

The speaker explains the complexities involved in working with pivot tables in VBA. They highlight how pivot tables are represented as objects with various sub-objects, making them more challenging to manipulate programmatically.

Working with Pivot Tables in VBA

  • The speaker acknowledges that pivot tables appear simple visually but are more complicated from a programming perspective.
  • In VBA, pivot tables are treated as objects within which different elements such as row labels, values, calculations, totals, and subtotals are stored.
  • Manipulating pivot tables programmatically requires a clear understanding of the object model and how different objects are linked together.
  • They caution that even seemingly simple operations like changing the layout or adding elements to a pivot table can involve writing a significant amount of code.

Importance of Understanding Object Model in VBA

The speaker emphasizes the importance of understanding the object model in VBA for effective coding. They explain how certain properties and actions belong to specific objects, highlighting the need for clarity on this concept.

Understanding Object Model in VBA

  • The speaker uses the example of changing cell color to illustrate the importance of understanding the object model.
  • While visually we perceive a cell as having a color, in VBA, the color property belongs to an object called "interior."
  • To change the color of a cell (e.g., B3), one must access and modify its interior object rather than directly modifying the cell itself.
  • Lack of familiarity with the object model can lead to confusion and difficulties when working with VBA code.

Challenges with AI Assistants for Coding

The speaker discusses potential challenges when using AI assistants like Chat GPT for coding tasks. They highlight that while these assistants can generate code, customization and understanding of underlying models may be required.

Challenges with AI Assistants for Coding

  • The speaker cautions that AI assistants like Chat GPT may provide solutions that are over-engineered or require extensive knowledge of underlying models.
  • Customizing or modifying code generated by AI assistants might be challenging without sufficient familiarity with programming concepts.
  • They suggest considering alternatives or investing time in learning before relying heavily on AI assistants for complex coding tasks.

This summary covers key points from selected sections of the transcript.

[t=0:57:58s] To-Do List and Activities

In this section, the speaker explains the concept of a to-do list and activities in the context of an application called "Awesome Chocolates." The speaker discusses how each person is assigned activities and is expected to mark them as done with a timestamp.

Creating the To-Do List

  • The to-do list is simple, starting with basic functionality and gradually adding complexity.
  • Each person is assigned a set of activities in Awesome Chocolates.
  • When an activity is completed, it should be marked as "done" along with the date and time of completion.

Structure of the To-Do List

  • The to-do list consists of three columns: Activity, Status, and Timestamp.
  • The heading for these columns will be bold and underlined.
  • The actual activities will be listed under the Activity column.

Using Cells instead of Tables

  • Instead of using tables, cells are used for simplicity.
  • VBA treats tables as separate objects called list objects, which can complicate things.
  • By using cells, it becomes easier to perceive and work with the data.

Filling Activities

  • A sample set of 21 activities (Activity 1 to Activity 21) is filled in for demonstration purposes.
  • As activities are completed, they should be marked as "done" with a corresponding timestamp.

Automating Marking Activities as Done

  • Rather than manually typing "done" and timestamps for each activity, a macro called "Mark as done" can be used.
  • This macro should run when a specific cell is selected by the user.
  • Initially, it should only run when selecting the Status column (Column C).
  • Later on, customization options can be added.

Writing Custom Code for Automation

  • It's recommended not to use the recorder but instead write the code manually.
  • This allows for better understanding of the logic flow and potential errors.
  • The code should ensure that it doesn't overwrite cells unintentionally.

Selecting the Status Column

  • To keep things simple, initially, the macro will only run when the user is on the Status column (Column C).
  • If the user tries to run the macro from a different location, it should not execute.

Adding a New Module

  • A new module can be added in VBA to contain chunks of code.
  • Right-clicking on "Module" allows inserting a new module.
  • Other options like User Form or Class Module can be explored later.

Writing the "Mark as Done" Subroutine

  • In the newly added module, a subroutine called "Mark as done" is created.
  • The name follows camel case convention (MarkAsDone).
  • Spaces and special characters are not allowed in subroutine names.
  • Camel case is preferred over underscore usage.

**** The summary has been provided based on the given transcript.

Working with the Selection Object

In this section, the speaker discusses the selection object and its limitations when working with different types of cells. They introduce an alternative object called "active cell" that represents the currently selected cell.

The Selection Object

  • The selection object is tricky to work with because it only has meaning in the context of a cell.
  • If you try to access selection.value, it will only work if a single cell is selected.
  • To overcome this limitation, consider using other options like the "active cell" object.

The Active Cell Object

  • The active cell represents the currently selected cell where your cursor is located.
  • It is useful for editing and performing actions on the active cell.
  • Unlike the selection object, which can hold a range of cells, the active cell refers to the top-left corner of your selection.

Accessing Values

  • To access values in VBA, you can use activeCell.value assuming you are already on column C.
  • This allows you to perform actions or manipulate data based on the value of the active cell.

Different Ways to Run Macros

  • Besides assigning macros to buttons or right-clicking, you can also switch to the Visual Basic editor for testing purposes.
  • By keeping both Excel and VBA windows visible, you can select a cell and run code directly from within VBA editor.
  • This method is helpful when testing multiple macros or specific parts of code without creating numerous buttons.

Running Macros with Precondition Checks

  • It's important to implement checks before running macros that rely on specific preconditions being met.
  • For example, ensuring that we are on column C before executing certain actions.
  • One way to check is by using activeCell.Column property and examining its value.

Implementing Precondition Checks

In this section, the speaker demonstrates how to implement a check to ensure that the macro is only executed when the active cell is in a specific column.

Checking the Active Cell Column

  • To determine the column of the active cell, use activeCell.Column property.
  • This property returns the column number of the active cell.
  • By checking this value, you can verify if it matches your desired column before proceeding with further actions.

Self-Learning VBA Language

  • To explore available methods and properties for an object, select it and press dot (.) in VBA editor.
  • This will display a list of available options that can be used with that object.
  • For example, typing column after pressing dot will show relevant properties or methods related to columns.

Running Macros and Handling Errors

In this section, the speaker discusses different ways to run macros and highlights potential issues with undoing actions performed through Visual Basic Editor.

Running Macros from VBA Editor

  • While viewing code in VBA editor, place the cursor inside a sub or function where you want to start running code.
  • You can then execute the code by clicking on the run button or pressing F5.
  • This method allows you to test and debug macros without creating multiple buttons.

Limitations of Undoing Actions in VBA

  • Actions performed through Visual Basic Editor cannot be undone using Ctrl+Z or Excel's undo feature.
  • If mistakes are made while executing code, there is no built-in way to revert those changes.
  • It is crucial to be cautious when implementing VBA in workbooks and consider writing robust and error-handling code.

Macro Behavior Based on Selection

In this section, the speaker explains how the macro's behavior is affected by the selection made in Excel.

Macro Behavior with Different Selections

  • The macro we've implemented only works as intended when certain preconditions are met.
  • If a single cell is selected, it will print "done" in that cell.
  • However, if a range of cells or non-cell elements are selected, the behavior may not be as expected.

Limitations and Considerations

  • The macro assumes that you have already selected column C before running it.
  • It is important to ensure that the preconditions for the macro are satisfied to achieve the desired results.

Best Practices and Conclusion

In this final section, the speaker emphasizes best practices when working with VBA and concludes the session.

Best Practices for VBA Implementation

  • When implementing VBA in workbooks, it is advisable to take backups or follow good coding practices.
  • Writing bulletproof code can help avoid unintended consequences and minimize errors.

Interacting with Viewers

  • The speaker briefly glances through the chat but mentions that they prefer interacting with viewers during live streams rather than just recording videos.
  • They encourage viewers to ask questions and engage in discussions related to the topic.

Q&A Interaction and Final Thoughts

In this section, the speaker addresses viewer comments and questions while wrapping up the session.

Engaging with Viewers

  • The speaker acknowledges interesting questions from viewers but reiterates their intention to interact and provide assistance during live streams.
  • They express their willingness to help viewers by sharing ideas and discussing various concepts related to VBA programming.

Checking Active Cell Column Before Execution

In this section, the speaker continues discussing how to check the active cell column before executing further actions in the macro.

Checking Active Cell Column

  • Before proceeding with actions in the macro, it is important to verify that the active cell is in the desired column.
  • One way to do this is by using activeCell.Column property and examining its value.

Exploring Object Properties

In this section, the speaker demonstrates how to explore object properties using VBA's self-learning capabilities.

Self-Learning VBA Language

  • To learn about available methods and properties for an object, select it and press dot (.) in VBA editor.
  • This will display a list of options that can be used with that object.
  • Using debug.print can help understand what a specific property returns.

Understanding Column Property

In this section, the speaker explains how to use the Column property of an object to determine its column number.

Using Column Property

  • The Column property returns the column number of an object (e.g., active cell).
  • By checking this value, you can determine if it matches your desired column before proceeding with further actions.

Conclusion and Final Remarks

In this final section, the speaker concludes their explanation on implementing precondition checks and exploring object properties in VBA programming.

Wrapping Up

  • The speaker concludes by mentioning that implementing checks based on preconditions is essential for ensuring macros work as intended.
  • They highlight the importance of being cautious when working with VBA code and suggest writing robust code to avoid unintended consequences or errors.

Printing Active Cell Column

In this section, the speaker demonstrates how to create a macro that prints the active cell column in the immediate window. The code checks if the active cell is in column 3 and marks it as "done" if true.

Creating the Macro

  • When running the macro, it prints the active cell column in the immediate window.
  • The message is printed underneath where all messages and alerts are displayed.
  • Select a cell and run the macro to see the column number printed.

Using If Condition

  • Check if activeCell.column is equal to 3 before setting it as "done".
  • If activeCell.column is 3, set activeCell.value as "done".
  • This demonstrates how to write an if condition in VBA.

Limiting Actions to Column 3

  • Only perform actions when on column 3 (activeCell.column = 3).
  • Edit text and change it to "Mark as done".
  • Assign this macro so that switching back and forth is not required.
  • If not on column 3, no action will be taken.

Adding Timestamp for Completed Tasks

In this section, the speaker explains how to add a timestamp when marking a task as "done". They suggest limiting actions based on the size of the to-do list cells.

Base Condition Check

  • The base condition check of being on column C (column 3) is not sufficient.
  • To be more careful, limit actions based on cells with activity (to-do list).

Adding Timestamp

  • When a task is marked as "done", add a timestamp.
  • Calculate time value using VBA code.

Declaring Variables and Storing Time Value

In this section, the speaker demonstrates how to declare variables and store the current time value for adding a timestamp.

Declaring Variables

  • Declare a variable using dim keyword.
  • Declare timeNow as the variable name.

Storing Time Value

  • Store the current time value in timeNow.
  • Use now function to get the current time.

Adding Timestamp in Next Column

In this section, the speaker explains how to add a timestamp in the next column using VBA code.

Going to Next Column

  • Use activeCell.offset to go to the next column.
  • Specify 0 rows and 1 column offset (activeCell.offset(0, 1)).

Testing Code

  • Test code by typing it out or using the immediate window.
  • The immediate window is useful for testing small pieces of code.
  • Print values like now or check properties like activeCell.column.

These are the main points covered in the transcript.

Introduction to VBA Code

The speaker discusses the VBA code and introduces concepts such as if-branch conditions, declaring variables, and offsetting and storing values.

Understanding the VBA Code

  • The speaker mentions that certain actions in different locations wouldn't have any effect.
  • They mention the ability to change the formatting of a specific value.
  • Precision in seconds is mentioned as a potential enhancement for the code.

Questions and Discussions

The speaker encourages questions from the audience and acknowledges ongoing discussions.

Interesting Discussions

  • Attila suggests avoiding overwriting headers by checking if the active cell value is not equal to "status".
  • The speaker agrees that limiting operations to a specific range would be a better approach.

Thinking of Enhancements

The speaker invites suggestions for enhancements to make the code more user-friendly.

Handling Already Completed Activities

  • The speaker raises an issue where marking an already completed activity as done would overwrite the timestamp.
  • They discuss whether this behavior should be considered a feature or a bug, leaving it up to individual interpretation.
  • Two possible approaches are presented:
  • Preventing redoing activities that are already marked as done.
  • Allowing amendments to already completed activities by changing timestamps.

Adding Checks for Column Three

The speaker proposes adding additional checks before setting values in column three.

Avoiding Timestamp Overwrite

  • It is suggested not to perform timestamp operations if an activity has already been marked as done.
  • A new variable called "car value" is declared to store the current value of the cell.
  • Option Explicit is mentioned as a good practice to ensure all variables are declared before use.

Variable Declaration and Type

The speaker discusses variable declaration and the benefits of specifying data types.

Declaring Variables

  • The speaker declares the variable "car value" and explains the importance of declaring variables.
  • Option Explicit is recommended to enforce variable declaration.
  • Without Option Explicit, VBA will create variables on the fly, but it's better to declare them explicitly for clarity and error prevention.

Timestamps have been associated with relevant bullet points in accordance with the provided transcript.

[t=1:25:31s] Handling Car Values and Conditions

In this section, the speaker discusses how to handle car values and conditions using VBA code.

Declaring Variables and Checking Conditions

  • Declare a variable to hold the current value of the car.
  • Check if the car value is not equal to "done" using an if condition.
  • If the condition is true, perform certain operations.

Displaying a Message for Already Completed Tasks

  • If the task is already completed, display a message box with a message like "You've already finished this dummy."
  • Use MsgBox method with appropriate parameters to show the message box.

Providing User Choice for Overwriting Timestamp

  • Instead of just displaying a message, provide a choice to the user whether they want to overwrite the timestamp or not.
  • Show a message box with options like "Do you want to overwrite the timestamp?" and buttons for OK and Cancel.
  • Based on user selection, branch out further code execution.

[t=1:30:51s] Archiving Completed Activities

In this section, the speaker introduces the idea of archiving or removing completed activities from view.

Changing Font Color for Completed Activities

  • Scan through the list of activities and identify those that are marked as done.
  • Change the font color of these completed activities to make them less noticeable.
  • This can be achieved either through VBA code or by applying conditional formatting in Excel.

Using Excel Features Instead of VBA

  • Consider using Excel's built-in features like conditional formatting instead of writing VBA code for simple tasks.
  • Excel has features that can make VBA code unnecessary, allowing for a more efficient workflow.
  • Embrace the idea of being lazy and finding ways to accomplish tasks with fewer steps.

The transcript is in English, so the notes are also provided in English.

[t=1:32:48s] Formatting Font Color in Excel with VBA

The speaker discusses how to format font color in Excel using VBA coding. They emphasize the importance of learning VBA and demonstrate how to loop through a list and change font color for each item.

Using VBA to Format Font Color

  • The speaker mentions that by using VBA, it is possible to automatically format font color based on certain conditions.
  • They explain the concept of looping through a list and performing an action for each item, which can be achieved using VBA.
  • The speaker invites questions or comments from the audience.
  • They address a comment suggesting that Python is more powerful than Excel, stating that Excel can solve almost everything when used effectively.
  • The speaker encourages users to view Excel and Python as different tools in their toolbox, rather than limiting themselves to one or the other.
  • They highlight that while Python may be preferred for complex tasks like machine learning, Excel can still be used effectively for most other cases.
  • The speaker advises against having a narrow mindset towards programming languages and suggests exploring the possibilities offered by both Excel and Python.
  • They encourage users to think of these tools as complementary rather than mutually exclusive.

Learning VBA

  • In response to a question about learning VBA, the speaker recommends starting with the recorder tool in Excel, which generates code snippets based on user actions.
  • They suggest using online resources and forums, such as ChatGPT, to seek guidance and ask questions about VBA coding.
  • The speaker mentions the availability of books on VBA programming, such as "VBA Power Programming," which can provide a more comprehensive understanding of VBA concepts.
  • They note that while the Visual Basic Editor may have minor differences across Excel versions, the core principles of VBA remain consistent.

Additional Functionality

  • The speaker briefly discusses the idea of moving completed tasks to a separate sheet in Excel but suggests caution due to potential complications when dealing with multiple sheets.

Timestamps are provided for each bullet point based on the given transcript.

Looping and Formatting in VBA

In this section, the speaker discusses the concept of looping through data in VBA and demonstrates how to apply formatting to cells using macros.

Looping Through Data

  • The key idea is to loop through things, allowing for repetitive actions.
  • Once you understand how to loop, you can easily add instructions by copying and pasting.
  • Looping is useful for tasks like scanning through data and making changes based on certain conditions.

Applying Formatting with Macros

  • The speaker wants to change the color of completed tasks in a worksheet.
  • A macro can be recorded to select the desired formatting options without needing to know the underlying code.
  • By recording a macro, the speaker demonstrates how to change text color, apply bold effect, and add background color.
  • The resulting VBA code includes instructions for making text bold and changing interior color.

Creating a Macro for Highlighting Completed Activities

  • The speaker plans to create a separate macro called "highlight done" that will visually highlight completed activities.
  • This separate macro allows marking activities as done individually before running the highlighting macro.
  • The intention is to go through the activity list and apply specific formatting only if an activity is marked as done.

Setting Boundaries for Code Execution

  • It's important to set boundaries when writing code so that it only executes on specific ranges or conditions.
  • For example, instead of scanning an entire column (e.g., B:B), it's more efficient to specify a range like B4:B24 or dynamically determine the last cell with data.
  • Specifying the worksheet name along with range references can help avoid potential issues if sheet names are changed later.

Naming Variables Thoughtfully

  • The speaker emphasizes the importance of giving variables meaningful names.
  • Using descriptive names helps avoid confusion and makes code easier to understand and maintain.
  • An anecdote is shared about a news story where someone tried to give their child a name that violated certain rules, highlighting the importance of thoughtful naming.

Conclusion

In this section, the speaker concludes the discussion on looping and formatting in VBA.

  • No specific content was provided in this part of the transcript.

[t=1:46:13s] Range and Cell Selection

In this section, the speaker explains how to select a range of cells in Excel using VBA code.

Selecting a Range of Cells

  • A range can be either a single cell or multiple cells.
  • To select a range, use the syntax "startCell.End(xlDown)" where "startCell" is the starting cell and "xlDown" represents the direction to go until the last cell with a value.
  • The selected range will capture all the cells from the start cell to the last cell with a value.

Checking and Highlighting Cells

  • To check if a neighboring cell is marked as "done," use the condition Cell.Offset(0, 1).Value = "done".
  • If the condition is true, apply font coloring and bold effect to highlight the current cell.
  • Use VBA color codes for font coloring and background color effects.

Looping through Cells

  • Use a For Each loop to iterate through each cell in the selected range.
  • Apply formatting only to cells that meet certain conditions (e.g., if neighbor says "done").
  • Continue looping for each subsequent cell in the range.

[t=1:50:39s] Infinite Loops and Archival Process

This section discusses potential issues with infinite loops in VBA code and introduces an archival process using copying and pasting rows.

Infinite Loops

  • Infinite loops occur when a loop keeps running without knowing when to quit.
  • For each loops usually don't encounter infinite loop issues since they run against finite collections of objects.
  • However, be cautious when writing conditions or loops that rely on specific conditions being met. Ensure there is an exit condition to prevent infinite looping.

Archival Process

  • Instead of highlighting cells, consider copying rows and pasting them onto another sheet for archival purposes.
  • This process involves selecting a row, copying it (Ctrl+C), navigating to another sheet, and pasting the copied row.
  • Repeat this process for each desired row to create an archive of selected rows.

[t=1:52:29s] VBA vs. Python in Excel

The speaker briefly discusses the comparison between VBA, Python, and Office Scripts in Excel.

VBA, Python, and Office Scripts

  • Excel now supports built-in python code execution as well as office scripts.
  • VBA is a powerful tool for automating tasks in Excel and has been widely used for many years.
  • Python can also be used within Excel for scripting purposes.
  • Office Scripts provide additional scripting capabilities within Excel.

Choosing the Right Tool

  • The choice between VBA, Python, or Office Scripts depends on the specific requirements of the task at hand.
  • Consider factors such as familiarity with programming languages, complexity of the task, and available resources when deciding which tool to use.

Conclusion

The transcript provides an overview of using VBA code in Excel to select ranges of cells, check conditions, apply formatting effects, avoid infinite loops, and consider alternative processes like archiving rows. It also briefly touches on the comparison between VBA, Python, and Office Scripts in Excel.

[t=1:53:37s] Applying Filters and Adding Blank Rows

In this section, Vikrant discusses the process of applying filters and adding blank rows in Excel using VBA.

Applying Filters and Adding Blank Rows

  • Vikrant suggests recording the actions of applying filters and adding blank rows to understand the individual pieces of code required for these operations.
  • The intention behind filtering and adding blank rows should be clarified before performing these actions. It is important to consider if these operations need to be done in a specific order or if there are alternative methods.
  • Module level constants can be declared to make them accessible across different subroutines. This allows variables to be declared above all subs, making them accessible throughout the code.
  • VBA offers more functionalities beyond what has been shown in the video, such as adding events that trigger specific actions when certain conditions are met. For example, running a macro when clicking on a cell or double-clicking on it.
  • Enhancing functionality can include implementing features like automatically marking cells as "done" when double-clicked or restricting certain actions to specific columns.

[t=1:55:45s] Using Chat GPT Instead of Learning Excel in Power BI

In this section, Vikrant addresses whether using Chat GPT can replace learning Excel in Power BI.

Using Chat GPT Instead of Learning Excel in Power BI

  • While it is possible to use tools like Chat GPT, it is not recommended as a substitute for learning Excel or other technologies.
  • Temptation may arise to use such tools as shortcuts, but investing time and effort into learning these technologies will yield better results.
  • Rather than spending hours on tools like Chat GPT without gaining practical knowledge, it is advisable to invest time in learning and understanding the tools themselves.

[t=1:57:08s] Possibility of Future VBA Lessons

In this section, Vikrant discusses the possibility of future lessons on VBA.

Possibility of Future VBA Lessons

  • Vikrant expresses interest in conducting more live streams and creating additional videos on VBA if there is sufficient demand.
  • Dedicated videos on VBA are already available on the channel, and there is also an existing VBA course for those interested in further learning.
  • Viewers are encouraged to like the video, leave comments, and share it with others to indicate their interest in more VBA content.

[t=1:58:09s] Relevance of VBA in Today's Landscape

In this section, Vikrant discusses the relevance of VBA in relation to other technologies available today.

Relevance of VBA in Today's Landscape

  • The usage of VBA has decreased over time due to changes in Vikrant's work nature. As he now focuses more on teaching and YouTube content creation, there is less need for coding.
  • When working with Excel, Vikrant tends to utilize native features rather than writing extensive code. This approach reduces maintenance efforts and aligns with his principle of being lazy.
  • Features like conditional formatting can often replace the need for macros by automatically highlighting specific cells based on predefined rules.
  • The necessity for writing VBA code has reduced over time but may still be relevant depending on individual requirements.

The transcript provided does not cover all sections mentioned in the prompt.

[t=2:01:19s] Power BI and Power Query

In this section, the speaker discusses the use of Power BI and Power Query for data automation and analysis.

Using Power Query for Data Related Tasks

  • Power Query is a powerful tool in Excel that allows for data automation.
  • It can be accessed by going to the "Data" tab in Excel.
  • The speaker has plenty of videos on their channel and online courses that cover Power Query in depth.

Looping and Conditional Actions

  • For tasks involving looping through a list of items and performing certain actions, the speaker evaluates whether it can be achieved using built-in features or if coding is necessary.
  • Conditional formatting can be used for simple cosmetic highlighting, but more elaborate tasks may require formulas or VBA code.
  • With Lambda functions in Excel, it is possible to scan a list, apply operations like mapping or reducing, without resorting to VBA.

New Functions in Excel

  • Excel now offers new functions like VSTACK, FILTER, UNIQUE, which were not available a few years ago.
  • These functions provide alternatives to traditional VBA coding for various data operations.

When Excel Falls Short

  • If there are problems that cannot be solved with built-in Excel features or functions, other options need to be considered.
  • The choice of solution depends on where it needs to be implemented (e.g., personal computer or cloud-based).
  • If it's for personal use on a computer, writing VBA code can be an option. The speaker enjoys coding as a hobby.

[t=2:04:46s] Python in Excel

This section explores the use of Python within Excel and its limitations compared to standalone Python programming.

Excitement with Python Outside of Excel

  • The speaker enjoys working with Python outside of Excel due to its versatility and capabilities.

Limitations of Python in Excel

  • Excel's implementation of Python is limited to reading data and performing operations on cell values.
  • It cannot perform actions like highlighting or marking items as done within the Excel interface.
  • The speaker finds that Python in Excel lacks the excitement and functionality compared to standalone Python programming.

[t=2:05:57s] Office Scripts

This section discusses Office Scripts, their advantages, limitations, and integration with other Office platform tools.

Advantages of Office Scripts

  • Office Scripts can be run on a computer or online platforms like SharePoint.
  • They can integrate with other Office platform tools such as Power Automate, Power Apps, and Outlook.

Limitations of Office Scripts

  • Unlike VBA code, which only runs on a computer, Office Scripts can run in browsers and other online environments.
  • However, complex automation tasks may require integration with Windows API or similar functionalities not available in Office Scripts.

Use Cases for Automation

  • Examples include automating email generation with attachments and templates using data from Excel.
  • While there are rare cases where Office Scripts are useful for automation, most scenarios involve more involved tasks that may require VBA coding or integration with external systems.

The summary has been created based on the provided transcript.

Understanding the Use of VBA and Python in Excel Automation

In this section, the speaker discusses the use of VBA and Python for automating tasks in Excel. They explain their personal preference for VBA but also highlight the importance of considering specific requirements and constraints when choosing between the two languages.

The Role of VBA in Excel Automation

  • VBA (Visual Basic for Applications) allows users to automate tasks in Excel by writing code.
  • It provides the ability to connect different elements and automate processes with a single click.
  • The speaker considers VBA as their go-to choice for automating tasks in Excel.

Choosing Between Writing Code or Avoiding it

  • The speaker emphasizes the importance of evaluating whether code is necessary or if there are alternative solutions.
  • They mention that they try to avoid writing code whenever possible but enjoy taking it up as a challenge.
  • However, they acknowledge that some situations may require immediate action due to deadlines or client demands.

Selecting the Right Tool for Automation

  • Depending on specific requirements, different tools can be used for automation:
  • Python can be used when integration with SharePoint or other systems is needed.
  • Office Scripts can be suitable for deeply integrated automation within Excel 365.
  • VBA macros are recommended when clients request them or when compatibility across different versions of Excel is essential.

Learning VBA and Python

  • The speaker suggests learning both languages but prioritizing based on immediate needs:
  • If starting from scratch or having ample free time, learning Python first may be beneficial.
  • If already working extensively with Excel, learning VBA can immediately enhance productivity.

Exploring Python in Excel and Compatibility Considerations

In this section, the speaker addresses questions related to Python in Excel and its compatibility compared to VBA.

Python in Excel

  • The speaker mentions that they have recently uploaded a video on their channel about Python in Excel.
  • They encourage viewers to watch the video for insights into what Python can do in Excel and its limitations.

Compatibility of VBA and Python

  • VBA is highly compatible and works across various versions of Excel.
  • On the other hand, Python in Excel currently only works with Excel 365.
  • Office Scripts are also limited to Excel 365.
  • Considering compatibility issues, using VBA may be preferable when dealing with clients or users who have different versions of Excel.

Learning VBA and Python Based on Individual Needs

In this section, the speaker provides guidance on learning VBA and Python based on individual circumstances.

Choosing Between VBA and Python

  • The speaker suggests considering immediate needs when deciding which language to learn first.
  • If still in college or having ample free time, starting with Python may be beneficial.
  • However, if already working extensively with Excel, learning VBA can immediately enhance productivity.

Automating Approval Processes and Exploring Power Automate

In this section, the speaker addresses questions related to automating approval processes and explores the use of Power Automate as a potential solution.

Automating Approval Processes

  • For automating approval processes involving multiple conditions, Power Automate is recommended as an easier option.
  • The speaker suggests searching for resources or consulting experts well versed in Power Automate for assistance.

Accessing Code from the Provided File and Appreciating the Value of Learning VBA

In this section, the speaker concludes by providing instructions on accessing the code from the provided file and emphasizing the value of learning VBA.

Accessing Code in the Provided File

  • The speaker mentions that they will save and upload the file as a link in the video description.
  • Viewers can access the code by right-clicking on any sheet, going to "View Code" or "Developer," and finding the code there.

Value of Learning VBA

  • The speaker encourages viewers to try VBA even if they don't have immediate practical use for it.
  • They highlight that VBA is an easy language to learn and serves as a gateway to learning other languages.
  • Dismissing claims about VBA dying, they emphasize its longevity and relevance in Excel automation.

Timestamps are approximate and may vary slightly.

[t=2:14:54s] Conclusion and Next Steps

The speaker thanks the audience for joining the session and mentions that they will be available for a while longer. They also invite the audience to check out their weekly videos on the channel.

Next Month's Session and Weekly Videos

  • The speaker mentions that they will have another session next month around the same time.
  • They encourage the audience to check out their weekly videos, which are uploaded every Tuesday on the channel.

Simulating Master Relationships and Sharing Workbooks in a Network

  • A viewer asks about simulating a master relationship and sharing workbooks in a network.
  • The speaker requests clarification on what is meant by "simulating a master relationship."
  • The speaker suggests avoiding VBA for multiple user scenarios where simultaneous usage is required.
  • They recommend using forms like Microsoft Forms or other data entry forms to capture data, then automating data collection using tools like Power Automate, Power Query, VBA, or Office Scripts.
  • The speaker advises against relying solely on VBA due to its limitations and complexity when dealing with multiple users.

Testimonial for VBA

  • A viewer shares their positive experience with using Excel and VBA, stating that it saves them approximately 12 hours per week.

Early Morning Presentation

  • The speaker acknowledges starting the presentation at 5 AM but admits forgetting about daylight savings time.
  • Despite feeling tired due to staying up late celebrating their child's birthday, they express no regrets about conducting the session.

Appreciation from Subscribers

  • A viewer expresses gratitude as an old subscriber of the channel.

Recording Software for Excel Videos

  • A viewer asks about the software used for recording and creating Excel videos.
  • The speaker recommends TechSmith Camtasia as an amazing software for this purpose.

Insights on Immediate Window in Excel

  • A viewer requests more information about the features and capabilities of the Immediate Window for interacting with code in Excel.
  • The speaker explains that the Immediate Window allows running one line of code at a time and can be used for debugging purposes.
  • They suggest using it to print outputs or debug points during looping operations.

Coding Suggestions for Google Sheets

  • A viewer asks about coding suggestions for Excel work in Google Sheets.
  • The speaker mentions that Excel VBA is not compatible with Google Sheets.
  • They recommend sticking to formulas in Google Sheets but note that it has its own scripting language called Apps Script.

Timestamps have been associated with relevant sections as per the provided transcript.

New Section - VBA and Power Query Automation

In this section, the speaker discusses the compatibility of VBA with Power Query and the possibility of automating data extraction using Power Query.

How well does VBA work with Power Query?

  • VBA is an object-driven language and can only act on objects available to it.
  • The object model of Power Query and Power Pivot are not fully exposed to Excel, limiting what can be done inside Power Query through VBA.
  • Some manipulation of query objects may still be possible.
  • Ken Puls has done significant work in automating Power Query with VBA. His website, Excel Guru, provides tips and resources on this topic.

Understanding VBA

  • If you're unfamiliar with VBA or joined the stream late, it's recommended to rewind and watch the beginning for a better understanding.

Conclusion and Upcoming Plans

  • The speaker concludes the session after almost two and a half hours.
  • They express hope that everyone had fun during the session.
  • The speaker mentions their plans for preparing breakfast as well as celebrating a kid's birthday later in the day.
  • Additionally, they mention going out to a desert in the evening for some fun.

Protecting Code in VBA

  • It is possible to protect code in VBA, but it is not completely foolproof.
  • Additional measures such as compiling and distributing code as an executable may provide further security.

Timestamps have been associated with relevant bullet points based on provided information.

Video description

Learn how to develop VBA code to solve practical problems in this Masterclass. Code samples will be provided. šŸ“ Sample file (from the stream): https://files.chandoo.org/vba/live-demo.xlsm Timestamps: =========== 0:00 - Welcome message & hellos (skip this if you want) 12:00 - What is covered in this video (VBA intro, practical example, VBA vs. Python vs. Office Scripts) 16:20 - Introduction to VBA - What is it and when / where to use it? 26:54 - Using "Macro Recorder" and creating your first VBA macro - simple example 33:50 - Understanding the recorded macro 37:52 - Customizing the recorded macro by adding your own code 39:45 - Adding a button to run the macro 41:40 - Adding the macro to Excel ribbon 50:04 - ChatGPT and VBA... my thoughts 53:06 - VBA Object model - explained 57:55 - Creating a simple "TO DO List" App with VBA 1:12:40 - IF condition in VBA 1:15:03 - Adding time stamp (with variables in VBA) 1:20:35 - Showing a message with msgbox() 1:32:38 - Highlighting done activities (with conditional formatting) 1:33:46 - Python vs. Excel 1:39:30 - Highlighting done activities (with VBA) 1:42:30 - Writing a loop in VBA (For Each) 1:51:00 - Discussion about VBA vs. other technologies, Q&A and random musings (watch if you have time) #vba #excel ~ sub LikeAndShare() debug.print("Like and share this video. Thank you šŸ™") end sub