How to select a cell in a non-active sheet

MR Campbell

Board Regular
Joined
Aug 2, 2002
Messages
113
I have a routine where i wish to select a cell in a non-active sheet - when I mean select, I simply mean to place the "cursor" at this cell.


E.g. If SheetA is the active sheet and I want to place the cursor in cell "B2" on SheetB, the code below does not work :

Sheets("SheetB").Range("B2").Select

At the moment it generates an error message.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,343
Office Version
  1. 365
Platform
  1. Windows
Try something like this.
Code:
Sheets("SheetB").Activate
Range("B2").Activate
By the way why do you want to do this?

Is it just to set the focus on that cell once your code is finished?
 

MR Campbell

Board Regular
Joined
Aug 2, 2002
Messages
113

ADVERTISEMENT

Is this a solution ?

Will this cause the code to jump to SheetB ... I dont wish this to happen.
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,343
Office Version
  1. 365
Platform
  1. Windows
Actually both the posted codes will do that.

What do you actually want to do?
 

just_jon

Legend
Joined
Sep 3, 2002
Messages
10,473
Not like that, but you could use a sheet selection event so that whenever SheetB was activated the cursor would be in B2

But what is your goal in doing this?
 

tusharm

MrExcel MVP
Joined
May 28, 2002
Messages
11,029
Re: Is this a solution ?

As others have implied but not explicitly stated one cannot select a cell in a non-active sheet. Think about it this way. Imagine you want to highlight a phrase on a particular page in a book. How would you do it without turning to that page?

MR Campbell said:
Will this cause the code to jump to SheetB ... I dont wish this to happen.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,621
Messages
5,832,735
Members
430,160
Latest member
a_majda

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top