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
 

Jaafar Tribak

Well-known Member
Joined
Dec 5, 2002
Messages
7,493
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,800
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,800
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,493
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,493
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,082,244
Messages
5,363,981
Members
400,772
Latest member
solbebe

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top