
The VBAName string is the VBA Name of our Worksheet, on the other hand the Excel Name string is our Excel Name. On the right we have a screen from an example Workbook. When speaking about Worksheets in ThisWorkbook, the VBA Name of a Worksheet is not the same as the Excel Name of a Worksheet. Set ws = ThisWorkbook.Worksheets("Sheet1") 'Get Worksheet named "Sheet1" in ThisWorkbook Set ws = ThisWorkbook.Worksheets(1) 'Get first Worksheet in ActiveWorkbook Set ws = ThisWorkbook.Sheets("Sheet1") 'Get Worksheet named "Sheet1" in ThisWorkbook Set ws = ThisWorkbook.Sheets(1) 'Get first Worksheet in ThisWorkbook ThisWorkbook VBA Worksheets The Sheets and Worksheets collections Set ws = Worksheets("Sheet1") 'Get Worksheet named "Sheet1" in ActiveWorkbook Set ws = Worksheets(1) 'Get first Worksheet in ActiveWorkbook Set wsCollection = Worksheets 'Get entire collection of Worksheets Similarly we can use Worksheets instead of Sheets. Set ws = Sheets("Sheet1") 'Get Worksheet named "Sheet1" in ActiveWorkbook

Set ws = Sheets(1) 'Get first Worksheet in ActiveWorkbook Set wsCollection = Sheets 'Get entire collection of Worksheets Now that we have that behind us lets explore the different ways in which we can access Worksheets in VBA: ActiveWorkbook VBA Worksheets The Sheets and Worksheets collectionsĭim ws as Worksheet, wsCollection as Sheets Using a Range we can access its cells Values or Formulas. Worksheets on the other hand as you know can define Ranges (not the same a single cells).

Looking into a single Workbook we will notice it contains a collection of Worksheets. Each Application contains a collection of Workbooks. Further down the tree we have our Workbooks.

The Excel Application represents the entire Excel process. Secondly it makes sense to remind the Excel Object hierarchy.Īt the top, at the root we have our Excel Application. It is extra important to understand this difference and I encourage you to read my post on this topic first. ActiveWorkbook – refers to the Workbook which is in the topmost Excel Window.ThisWorkbook – refers to the Workbook in which the VBA macro is running.Before we start I want to stress and remind the difference between ActiveWorkbooks and ThisWorksbooks. Some Excel WorksheetsLets start with the basics.
#Excel for mac, using = between worksheets how to#
VBA Activesheet and how it compares to regular Worksheets, how to Select Worksheets, how to Activate Worksheets, Selecting vs Activating Worksheets… and everything else you need to know about the VBA Worksheet in general. Today we are going to learn about VBA Worksheets.
