Excel: Activate cells when workbook is opened

J

Jens Lenge

How can I set the active cell for several Excel worksheets from within
Workbook_Open()?

Let's say I have worksheets "Sheet1" and "Sheet2" and want to automatically
scroll to the upper left and activate cell "A4" of Sheet1 and cell "B2" of
Sheet2 at startup (if possible, without visually opening the sheets).

I tried...

Private Sub Workbook_Open()
Worksheets("Sheet1").Range("A4").Select
Worksheets("Sheet2").Range("B2").Select
End Sub

....but that just yields an error. Who can help?

Cheers, Jens
 
R

Ricardo Drizin

You cannot select a range in a worksheet that is not active.

You should .Activate worksheets before using Range.Select, and maybe you
should disable screenupdating to disable screen-flickering.

Private Sub Workbook_Open()
Application.ScreenUpdating = False
Worksheets("Plan1").Activate
Worksheets("Plan1").Range("A4").Select
Worksheets("Plan2").Activate
Worksheets("Plan2").Range("B2").Select
Worksheets("Plan3").Activate
Application.ScreenUpdating = True
End Sub

Ricardo Drizin
Mondial Informática
 

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