Article ID: 177834
Article Last Modified on 10/10/2006
Worksheets("Sheet1").Copy After:=Worksheets(Worksheets.Count)
Or, you moved or copied a worksheet from another workbook into the
workbook that contains the public variables.
Public X As Integer
Public Y As String
Sub Test()
' <Your code goes here.>
End Sub
Normally, public variables retain their values until you close the
workbook in which they are contained. However, if the conditions listed in
the "Cause" section of this article are true, the public variables may
unexpectedly lose their values. The following steps demonstrate this
problem.
Public X As Integer
Public Y As String
Sub CopySheet()
Worksheets("Sheet1").Copy After:=Worksheets(Worksheets.Count)
End Sub
Sub SetVars()
X = 5
Y = "Hello!"
End Sub
Sub ShowVars()
MsgBox X
MsgBox Y
End Sub
163435 VBA: Programming Resources for Visual Basic for Applications
Additional query words: XL97 XL98 vba vbe XL
Keywords: kbbug kbdtacode kbprogramming KB177834