From the course: Excel: Learning VBA

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Streamline code references using With…End With statements

Streamline code references using With…End With statements - Microsoft Excel Tutorial

From the course: Excel: Learning VBA

Streamline code references using With…End With statements

- [Instructor] Writing effective Excel VBA macros requires two related but distinct skills. The first skill is the knowledge of the Excel object model, and the second is efficiency. You need to be able to write code that runs quickly but that also can be written and read quickly. One way to increase your programming efficiency is to use with and blocks within your code. Rather than create an example by hand, I'll show you what happens when I record a macro that has me changing two aspects of the value in cell A1. To demonstrate, I will use the O2_08_With sample file and you can find that in the Chapter Two folder of the "Exercise Files" collection. This workbook contains a single worksheet. My goal is to create a macro, that is, record a macro that will change the formatting of the text in cell A1 so that it is in the Cambria font and 18 point in size. I'll start by clicking away so that we'll select cell A1 when we come back to…

Contents