ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   setting a copied worksheet (https://www.excelbanter.com/excel-programming/327453-setting-copied-worksheet.html)

Doug Glancy

setting a copied worksheet
 
Hello,

This works for me:
Set MyWorksheet = Worksheets.Add

This doesn't:
Set MyWorksheet = Worksheets("Sheet1").Copy

Is there a way to do the set and copy on one line or do I copy and then set
on the next line?

Thanks,

Doug Glancy



Chip Pearson

setting a copied worksheet
 
Doug,

The Copy method doesn't return anything, so you can't set a
variable to its result. You need two lines of code

Dim MyWorksheet As Worksheet
Worksheets("SHeet1").Copy after:=Worksheets(3)
Set MyWorksheet = ActiveSheet


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Doug Glancy" wrote in message
...
Hello,

This works for me:
Set MyWorksheet = Worksheets.Add

This doesn't:
Set MyWorksheet = Worksheets("Sheet1").Copy

Is there a way to do the set and copy on one line or do I copy
and then set
on the next line?

Thanks,

Doug Glancy





Doug Glancy

setting a copied worksheet
 
Thanks, Chip. That's what I had done, but your concise explanation helps me
understand it better.

Doug

"Chip Pearson" wrote in message
...
Doug,

The Copy method doesn't return anything, so you can't set a
variable to its result. You need two lines of code

Dim MyWorksheet As Worksheet
Worksheets("SHeet1").Copy after:=Worksheets(3)
Set MyWorksheet = ActiveSheet


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Doug Glancy" wrote in message
...
Hello,

This works for me:
Set MyWorksheet = Worksheets.Add

This doesn't:
Set MyWorksheet = Worksheets("Sheet1").Copy

Is there a way to do the set and copy on one line or do I copy
and then set
on the next line?

Thanks,

Doug Glancy








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

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