Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default can't copy a sheet within same workbook

I'm trying to make a copy of a sheet right after itself. I first tried
this:

Set oSummarySheet = Sheets("WP_DETAIL").Copy After:=Sheets("WP_DETAIL")

I get error:
"Compile error:
Expected: end of statement"

The editor highlights "After", so I try:

Set oSummarySheet = Sheets("WP_DETAIL").Copy(, Sheets("WP_DETAIL"))

Now I get a run-time error '424':
Object Required

The source sheet exists. In the immediate window, I do this:

?Sheets("WP_DETAIL").index
3

I thought it might be confused about what sheets collection, so I tried:

Set oSummarySheet = ThisWorkbook.Sheets("WP_DETAIL").Copy(,
ThisWorkbook.Sheets("WP_DETAIL"))

Got the run-time error 424 again.

What am I doing wrong?

Thanks,
Woody
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default can't copy a sheet within same workbook


Good evening Woody

I think you're making life a bit more difficult for yourself - which is
often the way with VBA - but this can be done fairly simply. Try this:

Sheets("WP_DETAIL").Copy After:=Sheets(1)

HTH

DominicB


--
dominicb
------------------------------------------------------------------------
dominicb's Profile: http://www.excelforum.com/member.php...o&userid=18932
View this thread: http://www.excelforum.com/showthread...hreadid=380253

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default can't copy a sheet within same workbook

Hi Woody,

Try:

Sub Tester()
Dim oSumarySheet As Worksheet
Sheets("WP_DETAIL").Copy After:=Sheets("WP_DETAIL")
Set oSummarySheet = ActiveSheet
End Sub

---
Regards,
Norman


"Woody" wrote in message
.119...
I'm trying to make a copy of a sheet right after itself. I first tried
this:

Set oSummarySheet = Sheets("WP_DETAIL").Copy After:=Sheets("WP_DETAIL")

I get error:
"Compile error:
Expected: end of statement"

The editor highlights "After", so I try:

Set oSummarySheet = Sheets("WP_DETAIL").Copy(, Sheets("WP_DETAIL"))

Now I get a run-time error '424':
Object Required

The source sheet exists. In the immediate window, I do this:

?Sheets("WP_DETAIL").index
3

I thought it might be confused about what sheets collection, so I tried:

Set oSummarySheet = ThisWorkbook.Sheets("WP_DETAIL").Copy(,
ThisWorkbook.Sheets("WP_DETAIL"))

Got the run-time error 424 again.

What am I doing wrong?

Thanks,
Woody



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default can't copy a sheet within same workbook

"Norman Jones" wrote in news:
:

Sheets("WP_DETAIL").Copy After:=Sheets("WP_DETAIL")
Set oSummarySheet = ActiveSheet


Thanks Norman, that worked perfectlty. Much better than my workaround of
making a blank sheet and copy/paste from source to target.

Woody
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy sheet cells into differnt workbook/sheet, How? IVLUTA Excel Discussion (Misc queries) 2 June 2nd 09 11:16 PM
Copy sheet to different workbook 3Nails Excel Discussion (Misc queries) 1 November 5th 08 07:28 PM
Copy sheet to new workbook Tim Excel Discussion (Misc queries) 5 April 28th 05 02:00 PM
automatic copy and paste from sheet to sheet in a workbook ramseyjramseyj Excel Programming 6 December 11th 04 12:37 AM
Copy sheet from one workbook to another workbook problem Ron de Bruin Excel Programming 3 August 5th 04 07:19 PM


All times are GMT +1. The time now is 08:00 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"