What is the default area for worksheets and cells and range?

When you just print worksheets (), what is the default area of ​​ActiveWorkbook or ThisWorkbook? For those who do not know these differences, they are extremely important, especially in Excel 2013, when you want macros to run when switching to different books.

+2
source share
1 answer

In the standard module, unskilled Worksheets() workers will always reference an ActiveWorkbook. In ThisWorkbook implicit qualifier is Me and it will refer to the contained book.

Similarly, unqualified Range() or Cells() (or Rows() / Columns() ) in the standard module will refer to ActiveSheet, but in the sheet code module, the implicit qualifier is Me , and will refer to the corresponding sheet.

 Unqualified... Where Implicit Qualifier -------------- -------------- ------------------- Worksheets(), ThisWorkbook Containing workbook (Me) Sheets() Any other module Active workbook (via [_Global]) Range(), Cells(), Sheet module Containing sheet (Me) Rows(), Columns(), Any other module Active sheet (via [_Global]) Names() 

The easiest way to avoid remembering all of this is to always have completely Worksheets links to Worksheets , Sheets , Range , Cells or Names .

Specify the participant’s call with Me when referring to ThisWorkbook in the code of this module or when referring to Sheet1 in the code of this module.

+14
source

Source: https://habr.com/ru/post/954430/


All Articles