PC Review


Reply
Thread Tools Rate Thread

activesheet error

 
 
BeSmart
Guest
Posts: n/a
 
      14th Mar 2010
Hi
I've done something wrong here and I can't work out what it is...
Error msg: "Compile Error: With object must be user-defined type, object,
or Variant"

Sub copylplan()
Dim mySheet As String

mySheet = ActiveSheet

With mySheet
.Copy After:=Sheets(Sheets.Count)
End With

With mySheet
.Name = "Extract Plan"
End With
End Sub
--
Thank for your help
BeSmart
 
Reply With Quote
 
 
 
 
OssieMac
Guest
Posts: n/a
 
      14th Mar 2010
Hi,

Set the variable as a Worksheet then use Set in the line to assign the
ActiveSheet to the variable.

You should realize that the variable remains the original ActiveSheet; it
does not become the new ActiveSheet after the copy and therefore it is the
original worksheet that gets renamed with the following code.

Sub copylplan()

Dim mySheet As Worksheet

Set mySheet = ActiveSheet

With mySheet
.Copy After:=Sheets(Sheets.Count)
End With

With mySheet
.Name = "Extract Plan"
End With

End Sub


If you want to apply the name to the new sheet then as follows.

Sub copylplan()

Dim mySheet As Worksheet

Set mySheet = ActiveSheet

With mySheet
.Copy After:=Sheets(Sheets.Count)
End With

With ActiveSheet
.Name = "Extract Plan"
End With

End Sub


You can then still reference the original worksheet like follows.

mySheet.Activate


--
Regards,

OssieMac



 
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
Use a password in VBA ActiveSheet.protect & ActiveSheet.unprotect? Jim K. Microsoft Excel Programming 2 2nd Jun 2008 08:09 PM
Copying new activesheet after other activesheet is hidden? Simon Lloyd Microsoft Excel Programming 1 20th Jun 2006 10:02 AM
ActiveSheet.Paste error in XP =?Utf-8?B?bm9zcGFtaW5saWNo?= Microsoft Excel Programming 1 10th Dec 2004 07:06 PM
If ActiveSheet = .. then - I get an error Eager2Learn Microsoft Excel Programming 2 3rd May 2004 05:19 AM
ActiveSheet.Paste Error =?Utf-8?B?TWF0dA==?= Microsoft Excel Programming 7 9th Jan 2004 11:12 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:58 PM.