ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Copying And Renaming Sheets XL2003 (https://www.excelbanter.com/excel-programming/362833-copying-renaming-sheets-xl2003.html)

Kevin H. Stecyk[_2_]

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



Tom Ogilvy

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




Kevin H. Stecyk[_2_]

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




All times are GMT +1. The time now is 09:12 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com