Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default Copying And Renaming Sheets XL2003

Hi,

XL 2003, Windows XP.

I have a question regarding copying and renaming sheets.

Sub Blah()

Dim oActiveSheet As Object

blah blah blah

Sheets("Duplicate").Copy Befo=Sheets("Duplicate")
'\ Set oActiveSheet = Sheets("Duplicate(2)").Select
Set oActiveSheet = ActiveSheet

End Sub

The commented line when uncommented does not work. I get a Run-time error
'9': Subscript out of range.

Yet the next line does work. Why doesn't the commented line work? What did
I do incorrectly? It doesn't seem to matter whether or not I have ".Select"
appended to the statement.

When I copy, there are no other copies of "Duplicate". VBA appears to name
the duplicate of "Duplicate" to "Duplicate (2)". So I am puzzled.

Thank you.

Best regards,
Kevin


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Copying And Renaming Sheets XL2003

this worked for me in xl2003

Sub copysheets()
Dim oActivesheet As Worksheet
Sheets("Duplicate") _
.Copy Befo=Sheets("Duplicate")
Set oActivesheet = Sheets("Duplicate (2)")

MsgBox oActivesheet.Name
End Sub

In think your problem is the select on the end.

--
Regards,
Tom Ogilvy


"Kevin H. Stecyk" wrote:

Hi,

XL 2003, Windows XP.

I have a question regarding copying and renaming sheets.

Sub Blah()

Dim oActiveSheet As Object

blah blah blah

Sheets("Duplicate").Copy Befo=Sheets("Duplicate")
'\ Set oActiveSheet = Sheets("Duplicate(2)").Select
Set oActiveSheet = ActiveSheet

End Sub

The commented line when uncommented does not work. I get a Run-time error
'9': Subscript out of range.

Yet the next line does work. Why doesn't the commented line work? What did
I do incorrectly? It doesn't seem to matter whether or not I have ".Select"
appended to the statement.

When I copy, there are no other copies of "Duplicate". VBA appears to name
the duplicate of "Duplicate" to "Duplicate (2)". So I am puzzled.

Thank you.

Best regards,
Kevin



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default Copying And Renaming Sheets XL2003

Tom Ogilvy
....
this worked for me in xl2003

Sub copysheets()
Dim oActivesheet As Worksheet
Sheets("Duplicate") _
.Copy Befo=Sheets("Duplicate")
Set oActivesheet = Sheets("Duplicate (2)")

MsgBox oActivesheet.Name
End Sub

In think your problem is the select on the end.


Thank you Tom. I got it to work. :)

Best regards,
Kevin


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
What is the maximum number of sheets you can have in xl2003? Ayo Excel Discussion (Misc queries) 2 March 19th 10 07:51 PM
Copying format controls - xl2003 Steve Jones Excel Discussion (Misc queries) 3 December 18th 08 02:21 PM
Renaming sheets with the same name after copying into a new workbo cdb Excel Discussion (Misc queries) 0 March 14th 06 04:25 PM
copying and renaming sheets Jan Eikeland Excel Programming 9 December 23rd 03 07:55 PM
Copying and renaming worksheets John Young Excel Programming 1 December 17th 03 01:46 AM


All times are GMT +1. The time now is 09:27 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"