Rookie Question - Activating Worksheets

J

John V

This simple issue nags at me. In a larger macro, I start off activating a
worksheet and the current region, as follows:

ThisWorkbook.Activate
Worksheets("Transactions").Range("A1").Activate

[This inelegant code is about my fourth iteration at getting this right.]

I will run the macro from the VBA window, and if the Transactions worksheet
is not the active sheet when I start the macro, I will get the error message:
Activate method of Range class failed.

Seems to me that my code should work regardless of which workbook or
worksheet is active, but obviously I'm not understanding something. What is
it?

Thanks, John
 
S

Sam Wilson

You can write virtually any macro without using activate (it's faster when it
runs that way)...

But as a quick win, change:

Worksheets("Transactions").Range("A1").Activate

to

worksheets("Transactions").activate
range("A1").select
 

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