Thread: Variables
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Gary''s Student Gary''s Student is offline
external usenet poster
 
Posts: 11,058
Default Variables

You need to Dim you variable outside and before your Subs. This make them
"global".
--
Gary''s Student


"Mike" wrote:

Why do my variable seem to not be global? I have two subs:

Sub A()
Static CountRows As Long
CountRows = 1
MsgBox (CountRows)
End Sub

This one shows that CountRows = 1

Sub Bt()
Static CountRows As Long
MsgBox (CountRows)
End Sub

But when I run this one it does not remember CountRows = 1, and resets it to
zero. Why?