+ Reply to Thread
Results 1 to 3 of 3

one variable and use the variable for another sub in the same user form module ?

  1. #1
    Valued Forum Contributor
    Join Date
    11-04-2018
    Location
    Denpasar
    MS-Off Ver
    Excel 2010
    Posts
    777

    one variable and use the variable for another sub in the same user form module ?

    I have a simple Userform with one TextBox (CARI) and one ListBox (ListNama).
    The TextBox is used to search an item in a pivot table then added to the ListBox.

    Please Login or Register  to view this content.
    Except the first line (DrillTo),
    I get the rest of the code above from a senior member of this forum long time ago, and it works perfectly.

    I would like to have the "MyList" variable is defined on another sub,
    so I don't have to define it in CARI_Change sub.

    What I mean is something like this :
    Please Login or Register  to view this content.
    From the code above, I'm expecting that it already knows what are the items in MyList variable,
    because it already defined from another sub, for example at the Userform initialize, maybe something like this :

    Please Login or Register  to view this content.
    I wonder if it's possible to be done.

    Any kind of respond would be greatly appreciated.
    Thank you in advanced.

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

    Re: one variable and use the variable for another sub in the same user form module ?

    Move the declaration of MyList to the top of the userform module.

    Then you can set its value in the Initialize event and it will be available throughout the userform module.
    If posting code please use code tags, see here.

  3. #3
    Valued Forum Contributor
    Join Date
    11-04-2018
    Location
    Denpasar
    MS-Off Ver
    Excel 2010
    Posts
    777

    Re: one variable and use the variable for another sub in the same user form module ?

    It works.
    Thank you very much, Norie.

+ 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. Calling Function from Module to Form got an error Variable not set
    By atzdgreat in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-18-2017, 06:37 AM
  2. [SOLVED] Variable User-form object name
    By sur4j in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-12-2014, 10:27 AM
  3. [SOLVED] Global variable in user form
    By El_engineer in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-20-2014, 08:57 AM
  4. VBA: Create User Form That Takes Variable User Inputs
    By sanjeevpandey in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-18-2013, 06:14 PM
  5. [SOLVED] pass variable for user form module to function
    By maacmaac in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-10-2012, 10:10 PM
  6. Variable accross form to module
    By TonyforVBA in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-13-2010, 11:16 AM
  7. Increment Variable from User Form Selection
    By jonhfl in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 04-01-2010, 11:29 AM

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