Variable in Textbox Event

helivw

New Member
Joined
Oct 6, 2018
Messages
25
I make a selection in a Userform.Listbox with data coming form the Textbox in a Userform
Can I pass a variable to the Textbox Sub ..._Change event
ie. Sub TextBx_Change(ByRef ....)
I don't want to use a Public variable
Thanks
 

Some videos you may like

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

Jaafar Tribak

Well-known Member
Joined
Dec 5, 2002
Messages
7,582
Office Version
2016
Platform
Windows
I make a selection in a Userform.Listbox with data coming form the Textbox in a Userform
Can I pass a variable to the Textbox Sub ..._Change event
ie. Sub TextBx_Change(ByRef ....)
I don't want to use a Public variable
Thanks
Can you use the TextBox Tag Property to store the data ?
 

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
22,958
What is the data type of the array?
A delimited string and an array are pretty much the same information.
 

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
22,958
That would be a long delimited string. A module wide variable would be the easiest way to pass it. What is your concern about using a public variable?
 

helivw

New Member
Joined
Oct 6, 2018
Messages
25
That would be a long delimited string. A module wide variable would be the easiest way to pass it. What is your concern about using a public variable?
Because I read everywhere, you have to avoid using public variables and I use a lot of userforms (very handy) and each time I'm fighting of finding a easy way to transfer variables between my subroutine and parts (listbox, textbox, ...) of the userform and vv
 

Jaafar Tribak

Well-known Member
Joined
Dec 5, 2002
Messages
7,582
Office Version
2016
Platform
Windows
Can't you use module level variables instead of Public global variables - Each variable declared at the top of each userform module so you can use them throughout the entire userform lifetime and scope.
 
Last edited:

helivw

New Member
Joined
Oct 6, 2018
Messages
25
Can't you use module level variables instead of Public global variables - Each variable declared at the top of each userform module so you can use them throughout the entire userform lifetime and scope.
Thanks a lot Jaafar.
I really never thought that way, shame on me.

And what would be te best way to transfer my array to a userform Sub i.e. the userform initialize or whathever before my command
Userform.Show
 

Jaafar Tribak

Well-known Member
Joined
Dec 5, 2002
Messages
7,582
Office Version
2016
Platform
Windows
The userform Initialize event fires before showing the userform so that's a good place to populate the array.
 

Forum statistics

Threads
1,089,392
Messages
5,407,974
Members
403,174
Latest member
Zaibass

This Week's Hot Topics

  • help please
    SORRY NOT ANY GOOD AT EXCEL SO HELP WOULD BE MUCH APPRECIATED this formula is in a sheet called ignore...
  • two formulas needed
    Hello, I'll try my best to explain this: First formula needed in Sheet1 cell A2: If Sheet1 cell B2 = Sheet2 cell B2 then return a 1. If not then...
  • Dynamic Counts
    Good afternoon, we are tidying up some data & the data seems to be growing quicker than we are tidying it up! What we confirm (by reviewing it...
  • Help Excel formula eliminate duplicate values and keep only 2 identical rows.
    as picture below column A has a duplicate value. but the values are not the same as the rule. sometimes 4 rows, sometimes 10 rows or 7 or 9...
  • Macro Compile Error Sub or Function not defined
    Hello, I am trying to run macros from a validation list, all macros have been created and run perfectly on there own but I'm getting a compile...
  • Last row combined with Current Region VBA
    I'm generally happy finding the last row of data through something like Lastrow = Cells(Rows.Count, "D").End(xlUp) but I don't always receive data...
Top