Sheet.Activate versus Sheet.Select

shawnrpg

New Member
Joined
Oct 23, 2009
Messages
31
I can't find a good answer via searching (maybe I'm asking the wrong way).

When switching from one worsheet to another worksheet (within the same workbook), which is the preferred/correct way to switch,
Sheets("sheet name").Select or
Sheets("sheet name").Activate?

I am using Excel 2007.

Thanks,

Shawn
 
A new workbook (Book#) doesn't acquire an extension (.xls, .xlsx, whatever) until it's saved.
 
Upvote 0

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
One more point, my current code (where I actually switch between workbooks) work fine. It's just that I so many posts where Selecting and Activating slows he code down; I wanted to see if I could incorporate some of the things I read about into the current code.

Maybe I just have to leave well enough alone.

Thanks to all of you for taking the time to read/answer my questions; it is much appreciated.

Shawn
 
Upvote 0
A new workbook (Book#) doesn't acquire an extension (.xls, .xlsx, whatever) until it's saved.

Son...of...a.....
I removed the .xlsx from Book2 in the Destination portion and it worked! :oops:
The .xlsx was added (at a previous post's suggestion) because the code wasn't working and that appeared to be the only difference....must have been something else.

Again, THANKS TO ALL FOR YOUR TIME; you truely are geniuses (y)

Shawn
 
Upvote 0
Shawn

You might want to try something like this.

Note, it assumes you want to copy to the workbook the code is in.
Code:
Option Explicit
 
Sub CopyDataTest()
Dim wbDst As Workbook
Dim wbSrc As Workbook
 
    Set wbDst = ThisWorkbook ' creates a reference to the workbook code is in
    
    Set wbSrc = Workbooks.Open(Filename:= _
        "Q:\AIP\Teams\Estimating\Oracle System\End Use Programs.xlsx")
    
    wbSrc.Worksheets("End Use Programs").Range("A1:F5000").Copy wbDst.Worksheets("Sheet2").Range("A1")
    
End Sub

You could even take things further and create references for the worksheets and ranges.
 
Upvote 0

Forum statistics

Threads
1,213,568
Messages
6,114,348
Members
448,570
Latest member
rik81h

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