Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
PO PO is offline
external usenet poster
 
Posts: 66
Default Assigning worksheet to worksheet variable

Hi!

I'm trying to assign a copied worksheet to a worksheet variable using the
following code:

Dim sSheet As New Excel.Worksheet
Set sSheet = Sheets("Template").Copy(Befo=Sheets("Template") )

This doesn't work.

Any ideas?

TIA
PO


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Assigning worksheet to worksheet variable

Mot sure, but is this not acceptable?

Worksheets("Template").Copy Befo=Worksheets("Template")
Set sSheet = ActiveSheet


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"PO" <po wrote in message ...
Hi!

I'm trying to assign a copied worksheet to a worksheet variable using the
following code:

Dim sSheet As New Excel.Worksheet
Set sSheet = Sheets("Template").Copy(Befo=Sheets("Template") )

This doesn't work.

Any ideas?

TIA
PO




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Assigning worksheet to worksheet variable

Look in the object browser at Worksheet, Copy method. You see at the bottom
that it does not show "As Object"

The copy method does not return anything, so you can not set a reference to
it. (contrast with Worksheet, OleObjects method which is shown as "As
Object" and returns the OleObjects collection for the worksheet).

The workaround. When the sheet is copied, the copy is then the activesheet.

Dim sSheet As Excel.Worksheet
Sheets("Template").Copy(Befo=Sheets("Template") )
Set sSheet = Activesheet

I wouldn't use New in the declaration.

--
Regards,
Tom Ogilvy



"PO" <po wrote in message ...
Hi!

I'm trying to assign a copied worksheet to a worksheet variable using the
following code:

Dim sSheet As New Excel.Worksheet
Set sSheet = Sheets("Template").Copy(Befo=Sheets("Template") )

This doesn't work.

Any ideas?

TIA
PO




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Assigning worksheet to worksheet variable

When you remove the assignment, you need to remove the parentheses

Dim sSheet As Excel.Worksheet
Sheets("Template").Copy Befo=Sheets("Template")
Set sSheet = Activesheet

--
Regards,
Tom Ogilvy


"Tom Ogilvy" wrote in message
...
Look in the object browser at Worksheet, Copy method. You see at the

bottom
that it does not show "As Object"

The copy method does not return anything, so you can not set a reference

to
it. (contrast with Worksheet, OleObjects method which is shown as "As
Object" and returns the OleObjects collection for the worksheet).

The workaround. When the sheet is copied, the copy is then the

activesheet.

Dim sSheet As Excel.Worksheet
Sheets("Template").Copy(Befo=Sheets("Template") )
Set sSheet = Activesheet

I wouldn't use New in the declaration.

--
Regards,
Tom Ogilvy



"PO" <po wrote in message ...
Hi!

I'm trying to assign a copied worksheet to a worksheet variable using

the
following code:

Dim sSheet As New Excel.Worksheet
Set sSheet = Sheets("Template").Copy(Befo=Sheets("Template") )

This doesn't work.

Any ideas?

TIA
PO






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
Assigning a Worksheet Name to a Cell bcw_now Excel Worksheet Functions 3 May 14th 09 04:46 PM
Link variable data from one worksheet to another worksheet? T MAT New Users to Excel 3 November 27th 07 06:46 AM
Variable worksheet name (tab) linked to cell in same worksheet azbob Excel Worksheet Functions 6 January 9th 07 06:27 PM
Looking up a variable in one worksheet and copying information from another column to another worksheet?? Brad Torken Excel Discussion (Misc queries) 2 December 10th 06 06:02 AM
ASSIGNING A NEW NUMBER TO A WORKSHEET EVERY TIME IT IS OPEN steppie70 Excel Worksheet Functions 6 March 13th 06 09:52 PM


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