#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,101
Default Variables

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?
  #2   Report Post  
Posted to microsoft.public.excel.programming
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?

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
Not at all clear on use of variables and/or object variables JMay-Rke Excel Discussion (Misc queries) 11 July 4th 08 06:36 PM
Too Many Variables Heliocracy Excel Worksheet Functions 6 April 6th 07 07:02 PM
More than 1 Variables [email protected] Excel Discussion (Misc queries) 1 November 29th 06 02:09 AM
Using variables in RCs Mike D. Excel Programming 2 March 1st 05 10:53 PM
Variables No Name Excel Programming 2 July 9th 04 05:37 AM


All times are GMT +1. The time now is 09:47 PM.

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"