+ Reply to Thread
Results 1 to 4 of 4

Public Variable Lossing Value

  1. #1
    Forum Contributor
    Join Date
    06-18-2010
    Location
    USA
    MS-Off Ver
    Excel 2016
    Posts
    546

    Public Variable Lossing Value

    I have just created a userform and have declared the variable as
    Please Login or Register  to view this content.
    and the value is set like this
    Please Login or Register  to view this content.
    Now I used Application.Run as this is a module that I use in multiple Excel spreadsheets and I did not want to move all the syntax within the user form itself (if possible). Now in this procedure if I do a Debug.Print the value of emp is empty?

    Please Login or Register  to view this content.
    Why does the variable loose its value even though it has been declared as public?

  2. #2
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Public Variable Lossing Value

    Because you have to declare it public in a standard module not in the userform module.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  3. #3
    Forum Contributor
    Join Date
    06-18-2010
    Location
    USA
    MS-Off Ver
    Excel 2016
    Posts
    546

    Re: Public Variable Lossing Value

    Even thought the variable is public in the user form module, the standard module can not see it? But if the variable is public in a standard module the user form module can see it?

    Why is that?

  4. #4
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Public Variable Lossing Value

    Because a standard code module is always 'available' but a userform is only available when it is loaded

    ('Available' used to describe only, that's not a technical term - more correctly described as 'in scope')

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Public Variable and Static Variable Difference
    By zanshin777 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-18-2016, 01:58 AM
  2. [SOLVED] Public Variable
    By MarBoTJ in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-23-2015, 03:02 AM
  3. Public Variable value
    By nfpaccounting in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-11-2011, 02:34 PM
  4. Public Variable
    By Digitborn.com in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-09-2007, 03:54 PM
  5. Public variable
    By Jack in forum Excel - New Users/Basics
    Replies: 4
    Last Post: 03-18-2006, 05:40 PM
  6. [SOLVED] Public Variable not maintaining value.
    By Mark in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-07-2005, 03:05 PM
  7. [SOLVED] How to declare variable as public.
    By Mark in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-07-2005, 02:06 PM

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