+ Reply to Thread
Results 1 to 5 of 5

Declaring a variable as Public or Global

  1. #1
    Registered User
    Join Date
    03-26-2012
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    11

    Declaring a variable as Public or Global

    Dear Excel experts
    I am using a user form to obtain a user input. I want to use this user input in other user forms as well as modules while running a series of macros. The problem is that once the user form, in which the user input is collected is closed, that particular data is not available for use in other user forms and modules. Whenever I open another user form, the same input has to be collected over and again. As I scanned through various Excel help forums I gathered that the data I collect through the first user form must be declared as 'Public' or 'Global' so that it is available all through the project. But I can't figure out how to declare a variable as global or public. Can someone please help me to solve this.

    Thanks in advance
    Saji

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,820

    Re: Declaring a variable as Public or Global

    Hello saji. You declare the variable at the top of your macro before the 'sub' line ... example: this will declare x as a global variable and make it accessible by all modules
    Please Login or Register  to view this content.
    Last edited by Mumps1; 01-08-2013 at 04:14 PM.

  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Declaring a variable as Public or Global

    Why not just hide the userform?

    Then it's still accessible throughout.
    If posting code please use code tags, see here.

  4. #4
    Registered User
    Join Date
    03-26-2012
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Declaring a variable as Public or Global

    But how can I hide a user form?

    I use to unload it once I get out of it using 'Unload Me'

    saji

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Declaring a variable as Public or Global

    You can hide it like this.
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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