Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 102
Default activesheet error

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default activesheet error

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
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
ActiveSheet.Paste (error) Puzzled Excel Worksheet Functions 1 August 2nd 07 06:18 PM
activesheet paste error keys4worship Excel Programming 3 February 13th 05 09:10 PM
If ActiveSheet = .. then - I get an error Eager2Learn[_4_] Excel Programming 2 May 3rd 04 05:19 AM
ActiveSheet.Paste error Ron de Bruin Excel Programming 0 July 25th 03 12:39 PM


All times are GMT +1. The time now is 04:30 PM.

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"