sheet code problem

S

Stuart

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
 
T

Tom Ogilvy

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top