Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'workbooks.worksheets.activate' works, but '.select' does not

Tags:

excel

vba

Could anyone tell me why, when I refer to a particular sheet, I could use:

workbooks("A").worksheets("B").activate

but not

workbooks("A").worksheets("B").select 

?

like image 447
user2495069 Avatar asked Jul 01 '13 17:07

user2495069


Video Answer


1 Answers

You can't select a sheet in a non-active workbook.

You must first activate the workbook, then you can select the sheet.

workbooks("A").activate
workbooks("A").worksheets("B").select 

When you use Activate it automatically activates the workbook.

Note you can select >1 sheet in a workbook:

activeworkbook.sheets(array("sheet1","sheet3")).select

but only one sheet can be Active, and if you activate a sheet which is not part of a multi-sheet selection then those other sheets will become un-selected.

like image 108
Tim Williams Avatar answered Sep 29 '22 12:09

Tim Williams