Page 2 of 2 FirstFirst 12
Results 11 to 15 of 15

Thread: Variable in Textbox Event

  1. #11
    New Member
    Join Date
    Oct 2018
    Posts
    25
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Variable in Textbox Event

    Quote Originally Posted by Jaafar Tribak View Post
    The userform Initialize event fires before showing the userform so that's a good place to populate the array.
    Thanks for the quick reply.
    I not quite sure how to proceed so I give you an example what I'm doing
    ************
    Sub Example()
    Dim Arr() as variant, Arr1()

    Arr1=Range("F1:J200")
    Arr=Range("A1:E200")
    Userform1.Listbox1.List = Arr
    Userform1.Show

    end sub
    ************
    Now i have a textbox where each time the user enters a character my listbox is reduced in size
    In case of mistake of user I need again te full array in my listbox
    Sub tb_Char_Change()
    ...
    if there are no characters in tb_Char then the Listbox has 200 items
    If the user enters 1 character the listbox has only 100 items left
    if the user enters a second character the listbox has only 20 items left
    ....
    if the user enters a wrong character the listbox restart with the complete 200 items again

    So I need to transfer Arr from the normal procedure sub Example() to the userform where I can use Arr at several occasions
    because in the Subs of the userform I mix-up Arr1 and Arr

    Thanks a lot for helping me and sorry for the inconvenience

  2. #12
    New Member
    Join Date
    Oct 2018
    Posts
    25
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Variable in Textbox Event

    Quote Originally Posted by Jaafar Tribak View Post
    The userform Initialize event fires before showing the userform so that's a good place to populate the array.
    Thanks for the quick reply.
    I not quite sure how to proceed so I give you an example what I'm doing
    ************
    Sub Example()
    Dim Arr() as variant, Arr1()

    Arr1=Range("F1:J200")
    Arr=Range("A1:E200")
    Userform1.Listbox1.List = Arr
    Userform1.Show

    end sub
    ************
    Now i have a textbox where each time the user enters a character my listbox is reduced in size
    In case of mistake of user I need again te full array in my listbox
    Sub tb_Char_Change()
    ...
    if there are no characters in tb_Char then the Listbox has 200 items
    If the user enters 1 character the listbox has only 100 items left
    if the user enters a second character the listbox has only 20 items left
    ....
    if the user enters a wrong character the listbox restart with the complete 200 items again

    So I need to transfer Arr from the normal procedure sub Example() to the userform where I can use Arr at several occasions
    because in the Subs of the userform I mix-up Arr1 and Arr

    Thanks a lot for helping me and sorry for the inconvenience

  3. #13
    Board Regular Jaafar Tribak's Avatar
    Join Date
    Dec 2002
    Location
    Larache--Morocco
    Posts
    7,351
    Post Thanks / Like
    Mentioned
    39 Post(s)
    Tagged
    3 Thread(s)

    Default Re: Variable in Textbox Event

    Store the array in a userform module level temporary array upon activating the userform ...Something along these lines maybe:

    Code:
    Private vTempArr() As Variant
    
    Private Sub UserForm_Activate()
    
        vTempArr = ListBox1.List
    
    End Sub
    vTempArr should now contain the same data as Arr and the data and should be available throughout the entire userform module .
    Last edited by Jaafar Tribak; Aug 4th, 2019 at 02:49 PM.
    Office/Excel 2010 64Bits -- Win10 64Bits

    Common sense is not so common.


    http://photo-larache.blogspot.com/

  4. #14
    MrExcel MVP mikerickson's Avatar
    Join Date
    Jan 2007
    Location
    Davis CA
    Posts
    22,601
    Post Thanks / Like
    Mentioned
    20 Post(s)
    Tagged
    15 Thread(s)

    Default Re: Variable in Textbox Event

    If you want to get really slick, put this in the userform's code module

    Code:
    Dim arrArray as Variant
    '...
    
    Public Sub Start(inputArray as Variant)
        arrArray = inputArray
        Me.Show
    End Sub
    
    '...
    and invoke the userform with code like
    Code:
    Userform1.Start(Array(1, 2, 3))
    Last edited by mikerickson; Aug 4th, 2019 at 08:24 PM.

  5. #15
    New Member
    Join Date
    Oct 2018
    Posts
    25
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Variable in Textbox Event

    Really simple, but great. Thanks a lot

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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