Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 989
Default moving sheet changes object assignment?

I have a data sheet, which I had assigned to a worksheet variable, shData

I used code

shData.move after:=shADI

where shADI is another worksheet variable.

I just found out that doing this moves the worksheet just as I want, but the
object, shData loses it's assignment. It's not a problem, because I can just
reassign it after the move, but does anyone know why it loses the assignment?

Something to do with the internal workings of the object itself?

Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default moving sheet changes object assignment?

Hi Mark,

I just found out that doing this moves the worksheet just as I want, but
the
object, shData loses it's assignment.


This is not my experience.

I tried:
'=============
Public Sub Tester()
Dim shData As Worksheet
Dim shADI As Worksheet

Set shData = ThisWorkbook.Sheets("Sheet1")
Set shADI = ThisWorkbook.Sheets("Sheet3")

shData.Move after:=shADI

Debug.Print "shData", shData.Name
Debug.Print "shADI", shADI.Name

End Sub
'<<=============

The Immediate window returned:

shData Sheet1
shADI Sheet3


---
Regards,
Norman


"mark" wrote in message
...
I have a data sheet, which I had assigned to a worksheet variable, shData

I used code

shData.move after:=shADI

where shADI is another worksheet variable.

I just found out that doing this moves the worksheet just as I want, but
the
object, shData loses it's assignment. It's not a problem, because I can
just
reassign it after the move, but does anyone know why it loses the
assignment?

Something to do with the internal workings of the object itself?

Thanks.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 989
Default moving sheet changes object assignment?

Thanks, Norman.

Your reply made me notice that I forgot to mention an important piece of
information. shADI and shData were originally in different workbooks.

after the command:

shData.move after:=shADI

they are both in the same workbook, as desired, but the shData object has
lost its assignment.

"Norman Jones" wrote:

Hi Mark,

I just found out that doing this moves the worksheet just as I want, but
the
object, shData loses it's assignment.


This is not my experience.

I tried:
'=============
Public Sub Tester()
Dim shData As Worksheet
Dim shADI As Worksheet

Set shData = ThisWorkbook.Sheets("Sheet1")
Set shADI = ThisWorkbook.Sheets("Sheet3")

shData.Move after:=shADI

Debug.Print "shData", shData.Name
Debug.Print "shADI", shADI.Name

End Sub
'<<=============

The Immediate window returned:

shData Sheet1
shADI Sheet3


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default moving sheet changes object assignment?

Hi Mark,

Your reply made me notice that I forgot to mention an important piece of
information. shADI and shData were originally in different workbooks.


When the sheet object variable is set, the variable is explicitly, or
implicitly, qualified by the parent workbook. Moving the sheet to another
workbook is equivalent to adding a (new) copy of the sheet in the second
workbook and deleting the (original) worksheet in the first workbook.

As the original worksheet is deleted, the corresponding object variable is
set to nothing. If, rather than moving, you had copied the sheet to the
second workbook, the initial object variable would have continued to point
to the original sheet.

In either case, the 'new' sheet will have no corresponding object variable
unless, and until, it is set to such a (new) variable.

Otherwise expressed, there are two objects: the original sheet and the
copied sheet and the object variable is set to the former, not the latter.


---
Regards,
Norman



"mark" wrote in message
...
Thanks, Norman.

Your reply made me notice that I forgot to mention an important piece of
information. shADI and shData were originally in different workbooks.

after the command:

shData.move after:=shADI

they are both in the same workbook, as desired, but the shData object has
lost its assignment.

"Norman Jones" wrote:

Hi Mark,

I just found out that doing this moves the worksheet just as I want,
but
the
object, shData loses it's assignment.


This is not my experience.

I tried:
'=============
Public Sub Tester()
Dim shData As Worksheet
Dim shADI As Worksheet

Set shData = ThisWorkbook.Sheets("Sheet1")
Set shADI = ThisWorkbook.Sheets("Sheet3")

shData.Move after:=shADI

Debug.Print "shData", shData.Name
Debug.Print "shADI", shADI.Name

End Sub
'<<=============

The Immediate window returned:

shData Sheet1
shADI Sheet3




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 989
Default moving sheet changes object assignment?

gotcha. thanks.

for the app I'm building, it seems best to just reassign the shData object
after the move.

Thanks for the explanation.

Mark

"Norman Jones" wrote:

Otherwise expressed, there are two objects: the original sheet and the
copied sheet and the object variable is set to the former, not the latter.


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
formula for moving information from one sheet to another sheet Puzzled Excel Discussion (Misc queries) 4 June 6th 10 05:58 AM
Moving object MAX Excel Worksheet Functions 2 March 23rd 09 03:34 PM
moving informatiion from one sheet to a total sheet john Excel Discussion (Misc queries) 2 January 31st 08 10:17 PM
Automatically moving a drawing object in a chart Dan k Charts and Charting in Excel 1 February 7th 06 03:06 AM
Worksheet object assignment Heapy Excel Programming 0 September 18th 03 08:37 PM


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