+ Reply to Thread
Results 1 to 8 of 8

Variable scope

  1. #1
    Registered User
    Join Date
    03-10-2013
    Location
    N/A
    MS-Off Ver
    Excel 2010
    Posts
    62

    Variable scope

    Hi All:

    I have the following problem:

    Please Login or Register  to view this content.

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Thanks,

    Yossi
    Last edited by arlu1201; 03-12-2013 at 01:32 PM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,093

    Re: Variable scope

    The parameters you are passing to the subroutines are in single quotes and, therefore, being treated as comments. I couldn't actually get the code to run until I changed them to double quotes.

    Please Login or Register  to view this content.
    HTML Code: 

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,164

    Re: Variable scope

    Hi yossel and welcome to the forum,

    Here is the best explanation about scope I've found.
    http://www.cpearson.com/Excel/Scope.aspx
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,093

    Re: Variable scope

    @MarvinP: that is quite comprehensive,isn't it!? Although I was/am aware of Public/Private variable, modules, etc., I don't think I've ever seen it explained so clearly. Now I want a reason to define "Casper the Friendly Object Module" ... got to admit, I got to about tw thirds of the way down and my head started spinning

    Cheers, TMS

  5. #5
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,164

    Re: Variable scope

    @TM Back in the old days of BASIC (1980's) we needed to keep track of these DIMed variables and how they were placed on the stack. I remember winning a codeing competition because I placed my most frequently used variable first in the DIM statements. Variables were searched for starting at the first one defined (per subroutine) until found. If you placed the DIM statement for that variable at the end of all the DIM statements it took extra time to find it. Simply placing the most frequently used variable at the front allowed it to be found first and my code ran a lot faster.

    Global Dimed variables might be the answer to this OP question but it looks like s/he needs to determine where the variable is defined and how/if it is being addressed in the code.

  6. #6
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Variable scope

    yossel,

    Welcome to the forum.

    I have added code tags to your post. As per forum rule 3, you need to use them whenever you put any code in your post. Please add them in future. If you need more information on how to use them, check my signature below this post.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  7. #7
    Registered User
    Join Date
    03-10-2013
    Location
    N/A
    MS-Off Ver
    Excel 2010
    Posts
    62

    Re: Variable scope

    Thanks a lot. My problem was that I was watching the 'Watch' window, expecting the value to change, not realizing that it was referencing the foo from sub1.

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,093

    Re: Variable scope

    You're welcome. Thanks for the rep.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1