The ActiveWorkbook is not same to ThisWorkbook. Sheets("Sheet1").Range("A1").Select 'Will always select items from Worksheet named Sheet1 You might want to define the Worksheet reference by Range if you want your reference values from a specifc Worksheet: So beware as depending on your ActiveWorksheet the Range object will return values local to your worksheet: The Range object defaults to your ActiveWorksheet. Set myRange = Range("A1") 'Need to use Set to define myRange As the VBA Range is an object you need to use the Set statement: The Range is a separate object variable and can be declared as other variables. Select a cell or Range of cells using the Select method. Range("A1:B2").Activate 'Activate the cells and show them on your screen (will switch to Worksheet and/or scroll to this range. Range("A1:B2").Select 'Select the Cells A1:B2 in your Excel Worksheet Set r= Range(Range("A1"), Range ("B1")) 'Range of 2 cells A1 and B1 Set r = Range("A1:B2") 'Square Range of 4 cells - A1,A2,B1,B2 The Range is a Worksheet property which allows you to select any subset of cells, rows, columns etc.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |