Select row in the inactive sheet

kayza

Board Regular
Joined
Apr 29, 2015
Messages
61
Office Version
  1. 2007
Platform
  1. Windows
Hallo.

I have simple code to select row which located in the inactive sheet, and here is my code
Code:
Dim ws As Worksheet
Set ws = Sheets(2)
With ws
    .Select
    .Rows(7).Select
End With

how to select row in the inactive sheet (Sheet2) without abandon active sheet (Sheet1)
thanks in advance
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Cell selection can only be made on the active sheet.

But cell selection can normally be avoided (and should be avoided in the interest of efficiency).
For example, to copy row 7 from Sheets(2) and paste to row 12 of the active sheet :

Code:
Dim ws as Worksheet
Set ws = Sheets(2)
ws.Rows(7).copy Rows(12)

Or if you really wanted to select on another sheet and get back to the original active sheet :
Code:
Dim startWS As Worksheet, ws As Worksheet
Set startWS = ActiveSheet
Set ws = Sheets(2)
With ws
    .Select
    .Rows(7).Select
End With
startWS.Select
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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
Back
Top