PC Review


Reply
Thread Tools Rate Thread

Copying Worksheet from one workbook to another

 
 
Barb Reinhardt
Guest
Posts: n/a
 
      3rd Jul 2008
I have the following bit of code

Set newWS =
myWS.Copy(After:=CombinedWB.Sheet(CombinedWB.Worksheets.Count))

newWS and myWS are worksheets and CombinedWB is a workbook.

I'm getting a compile error (Expected Function or Variable) on COPY. What
am I missing? I've done this before and can't find the example.

Thanks,

Barb Reinhardt

 
Reply With Quote
 
 
 
 
Jim Thomlinson
Guest
Posts: n/a
 
      3rd Jul 2008
Copy does not return the new worksheet that it creates (unlike the add
method) so you can not set your worksheet reference to it. So for example
this works

Dim wks As Worksheet

Sheet1.Copy After:=Sheet3
Set wks = ActiveSheet

In your case it is going to be a tad bit more complicated. You can use the
index number of the sheet though to set your worksheet object. Untested but
this might do it...

myWS.Copy(After:=CombinedWB.Sheet(CombinedWB.Worksheets.Count))
Set newWS = CombinedWB.Sheet(CombinedWB.Worksheets.Count)

--
HTH...

Jim Thomlinson


"Barb Reinhardt" wrote:

> I have the following bit of code
>
> Set newWS =
> myWS.Copy(After:=CombinedWB.Sheet(CombinedWB.Worksheets.Count))
>
> newWS and myWS are worksheets and CombinedWB is a workbook.
>
> I'm getting a compile error (Expected Function or Variable) on COPY. What
> am I missing? I've done this before and can't find the example.
>
> Thanks,
>
> Barb Reinhardt
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copying Worksheet to New Workbook Orion Cochrane Microsoft Excel Programming 3 10th Nov 2008 05:03 PM
Copying worksheet to another workbook Dig Microsoft Excel Worksheet Functions 3 30th Oct 2008 09:01 PM
Copying a worksheet into the same workbook =?Utf-8?B?TWljaGFlbA==?= Microsoft Excel New Users 9 6th Feb 2006 08:35 PM
Copying A Worksheet From Each Open Workbook to an new Workbook =?Utf-8?B?Y2FybA==?= Microsoft Excel Worksheet Functions 1 3rd Jan 2006 05:37 PM
Copying each worksheet in a new workbook Eric1701 Microsoft Excel Worksheet Functions 1 3rd Sep 2004 09:08 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:33 AM.