ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Worksheet object assignment (https://www.excelbanter.com/excel-programming/277467-worksheet-object-assignment.html)

Heapy

Worksheet object assignment
 
I'm trying to assign a worksheet object to a variable at the time of its
creation through a copy function, but the process always fails with an
"Object Variable Not Set" error. i.e.:

Dim ns As Worksheet
Set ns = Sheets(GrpShellTemp).Copy(Befo=Sheets(GrpShellT emp))

.... while in another module, "GrpShellTemp" is defined as a constant:

Public Const GrpShellTemp As String = "GroupShell"



When the code runs, the sheet in question IS copied and is placed before the
one being copied, however the assignment fails and the error results.

I know I can get around this by simply allowing the copy function to run
without the assignment as follows:

Sheets(GrpShellTemp).Copy Befo=Sheets(GrpShellTemp)

.... and then assign the variable:

Set ns = ActiveSheet

.... but I shouldn't have to do this, should I? Why won't the assignment work
at the time the sheet is copied?

Thx
HWH




All times are GMT +1. The time now is 02:03 PM.

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