View Full Version : Activating cells/worksheets
Sandstedt
11-26-2008, 01:05 PM
Hi, I've got some questions about the Activate method.
When I have activated a specific worksheet and then want to activate a cell in that worksheet (you can't do both at the same time, right?), is it Ok to write it like this: (x and y are variables)
Worksheets("makro").Activate
Cells(y, x).Activate
Or does it have to be like this?
Worksheets("makro").Activate
Worksheets("makro").Cells(y, x).Activate
Also, if I run the code in debug mode bit by bit, and jump between the sheets manually while doing this, does this affect what the code refers to?
Kenneth Hobs
11-26-2008, 01:28 PM
Selecting or activating is seldom needed. The recorder has to do it but you don't.
The fist method will work.
e.g.
Sheet1.Activate
Range("C25").Select
Or use Goto:
Application.Goto Sheet1.Range("A200"), True
The answer to the last part is most likely, yes.
Sandstedt
11-26-2008, 01:42 PM
Selecting or activating is seldom needed. The recorder has to do it but you don't.
I see. I was thinking it would be more effective to use the Activate nethod since everytime I refer to Cells(x,y), Excel has to check the values of x and y. Maybe Excel is doing that anyway when using ActiveCell?
Also, does it matter if I use Range("A1") or Cells(1,1) in terms of performance?
Thank you for helping by the way.
Kenneth Hobs
11-26-2008, 02:48 PM
No difference. The advantage to Range is that intellisense will work.
If you didn't know, you can use Cells like this too:
MsgBox Cells(1, "A").Text
Sandstedt
11-26-2008, 02:51 PM
No difference. The advantage to Range is that intellisense will work.
If you didn't know, you can use Cells like this too:
MsgBox Cells(1, "A").Text
Didn't know that, thank you!
Sandstedt
11-26-2008, 04:16 PM
Sorry about the double post but I have a quick question.
If I use the GoTo method, does vba make the sheet I just went to the active sheet, or do I have to specify which sheet to go to next operation too?
Bob Phillips
11-27-2008, 06:12 AM
In Goto you can specify the sheet and the cell, and it beomes active.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.