ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   sheet code problem (https://www.excelbanter.com/excel-programming/316584-sheet-code-problem.html)

Stuart[_19_]

sheet code problem
 
with the following procedure entered into the sheet code of "Sheet1" the
method fails why?

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Sheets("Sheet2").Select
Range("A1").Select
End Sub


I can enter the above code into a normal macro in a normal module then call
that sub fro the sheet code. but that seems daft, why doesn't it work
directly?



stuart



Tom Ogilvy

sheet code problem
 
Because Range("A1").Select refers to the sheet containing the code, which
isn't the activesheet at that time

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Sheets("Sheet2").Select
Sheets("Sheet2").Range("A1").Select
End Sub

--
Regards,
Tom Ogilvy

"Stuart" wrote in message
...
with the following procedure entered into the sheet code of "Sheet1" the
method fails why?

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Sheets("Sheet2").Select
Range("A1").Select
End Sub


I can enter the above code into a normal macro in a normal module then

call
that sub fro the sheet code. but that seems daft, why doesn't it work
directly?



stuart






All times are GMT +1. The time now is 12:07 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com