Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Hi All, Can anyone explain why the following code does not work in a module: Sub SelAll() For Each Sht In ActiveWorkbook.Worksheets Sht.Cells.Select Next End Sub Whereas, the following code works fine in a worksheet code: Sub SelSht() Cells.Select End Sub I am guessing it is related to scope, but I cannot see why from my reading of the excel help files. Thanks in advance, Alan. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
You cannot select cells in other than the active sheet.
You must first select the sheet before selecting the cells. For example, this works: Sub SelAll() Dim Sht As Worksheet For Each Sht In ActiveWorkbook.Worksheets Sht.Select Sht.Cells.Select Next End Sub Your second code example works because it references the active sheet. The cells method, when not qualified, refers to the active sheet; i.e. the statement "Cells.Select" by default refers to the cells of the active sheet. Regards, Greg -----Original Message----- Hi All, Can anyone explain why the following code does not work in a module: Sub SelAll() For Each Sht In ActiveWorkbook.Worksheets Sht.Cells.Select Next End Sub Whereas, the following code works fine in a worksheet code: Sub SelSht() Cells.Select End Sub I am guessing it is related to scope, but I cannot see why from my reading of the excel help files. Thanks in advance, Alan. . |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
"Greg Wilson" wrote in
message ... You cannot select cells in other than the active sheet. You must first select the sheet before selecting the cells. For example, this works: Sub SelAll() Dim Sht As Worksheet For Each Sht In ActiveWorkbook.Worksheets Sht.Select Sht.Cells.Select Next End Sub Your second code example works because it references the active sheet. The cells method, when not qualified, refers to the active sheet; i.e. the statement "Cells.Select" by default refers to the cells of the active sheet. Thanks Greg, Much appreciated. Regards, Alan. |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Alan
As far as I know you can not select on a sheet that is not active try Sub SelAll() Dim sHt As Worksheet For Each sHt In ActiveWorkbook.Worksheets sHt.Activate sHt.Cells.Select Next End Su -- Message posted from http://www.ExcelForum.com |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
"mudraker " wrote in
message ... Alan As far as I know you can not select on a sheet that is not active try Sub SelAll() Dim sHt As Worksheet For Each sHt In ActiveWorkbook.Worksheets sHt.Activate sHt.Cells.Select Next End Sub Hi Mudraker, Thanks - much appreciated. Regards, Alan. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Up down arrow keys do not select cells if select locked cells unch | Excel Discussion (Misc queries) | |||
Macro to select cells without a certain value and select a menu it | Excel Worksheet Functions | |||
Using formulas to select cells (Ex: Select every nth cell in a col | Excel Discussion (Misc queries) | |||
code in module A to not execute a Worksheet_SelectionChange sub of another module | Excel Discussion (Misc queries) | |||
how do you "select locked cells" w/o "select unlocked cells"? | Excel Discussion (Misc queries) |