Select/Activate a Cell From Another Workbook

rootdown42

Board Regular
Joined
Jun 8, 2005
Messages
93
I have a template that, using VBA, makes a copy of itself, opens the copy, does a copy/paste-values over the data in each worksheet, and saves that copy. After its done and a user opens the copied file, all the cells on the worksheet are still selected from the Copy method, which I want to avoid. I attempted to add a Activate statement and later a Select statement into the code, but that just results in the always enjoyable "Run-time error 1004 - Select/Activate Method of Range class failed" error. The relevant code looks like this:
Code:
With wb
     For each ws in .Worksheets
          With ws
              .Cells.Copy
              .Cells.PasteSpecial Paste:=3
              Application.CutCopyMode = False
              .Cells(7, 6).Select   <---- Runtime Error
          End With
     Next ws
End With
I assume that its incorrect to use the Select method inside the With blocks - in fact I thought it was best practice to not use .Select or .Activate at all in my code - but I don't know any other method to unselect ever single cell within my copied file. Can anyone help?
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Hello,

What is 3? Values?

My thought would be to not select anything, e.g.,

Code:
     For each ws in wb.Worksheets
          With ws.UsedRange
              .Value = .Value
          End With
     Next ws
*untested - aircode*

Otherwise, check out the GoTo Method.
 
Upvote 0
Try this alternative approach

Code:
With wb
     For Each ws In .Worksheets
          With ws.UsedRange
            .Value = .Value
          End With
     Next ws
End With
 
Upvote 0
Thank you both for the reply. The UsedRange method property didn't work - maybe because I used Cells.Copy before the PasteSpecial? Regardless, the Application.Goto method seemed to have solved the problem.

And to answer your question NateO, yes, the 3 in
Code:
.Cells.PasteSpecial Paste:=3
is supposed to represent xlPasteValues. I used the numeric reference because it was a suggested work-around for an even worse problem I'm having with Automation Error that I'm encountering. Thanks again.
 
Upvote 0

Forum statistics

Threads
1,203,104
Messages
6,053,543
Members
444,670
Latest member
laurenmjones1111

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