ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   textbox array (https://www.excelbanter.com/excel-programming/384852-textbox-array.html)

jimmy[_5_]

textbox array
 
Hi all,

I remember that there is a setting in property window to make all the
textbox in an array, but not found in excel 2003 VBA, need to write code?

thanks



merjet

textbox array
 
One can make control array in VB (each control has the same name and
an index, and Index is a Property). Excel VBA (2003 at least) does not
offer this.

You can loop through all Textboxes on a UserForm like this:

For Each c In Me.Controls
If TypeName(c) = "TextBox" Then
Debug.Print c.Name
'do something else
End If
Next c
End Sub

Hth,
Merjet



jimmy[_5_]

textbox array
 
Thanks...but how to group them into an array?
How to code in the 'do something else ?

"merjet"
egroups.com...
One can make control array in VB (each control has the same name and
an index, and Index is a Property). Excel VBA (2003 at least) does not
offer this.

You can loop through all Textboxes on a UserForm like this:

For Each c In Me.Controls
If TypeName(c) = "TextBox" Then
Debug.Print c.Name
'do something else
End If
Next c
End Sub

Hth,
Merjet





merjet

textbox array
 
Thanks...but how to group them into an array?

They are in the Controls collection already. If you want them in an
array, you will have to build it youself.

How to code in the 'do something else ?


I don't know what you are trying to do or why you want them in an
array.

Merjet


jimmy[_5_]

textbox array
 
ic..I just want to get every textbox value and perform some calculation then
put the result in some cells. How to get the value of those textbox in the
controls collection?

"merjet"
groups.com...
Thanks...but how to group them into an array?


They are in the Controls collection already. If you want them in an
array, you will have to build it youself.

How to code in the 'do something else ?


I don't know what you are trying to do or why you want them in an
array.

Merjet




merjet

textbox array
 
ic..I just want to get every textbox value and perform some calculation then
put the result in some cells. How to get the value of those textbox in the
controls collection?


For Each c In Me.Controls
If TypeName(c) = "TextBox" Then
Debug.Print c.Value ' or c.Text
z = c.Value 'assign to variable
End If
Next c

c.Value is String, so convert or assign to a numeric variable to do
calcs.

Merjet





jimmy[_5_]

textbox array
 
Thanks
How do it define the sequence of textboxes? By the last number of its name?
"merjet"
egroups.com...
ic..I just want to get every textbox value and perform some calculation
then
put the result in some cells. How to get the value of those textbox in
the
controls collection?


For Each c In Me.Controls
If TypeName(c) = "TextBox" Then
Debug.Print c.Value ' or c.Text
z = c.Value 'assign to variable
End If
Next c

c.Value is String, so convert or assign to a numeric variable to do
calcs.

Merjet







merjet

textbox array
 
How do it define the sequence of textboxes? By the last number of its name?

Yes, if you accepted the default names Textbox1, Textbox2, etc.

Merjet



All times are GMT +1. The time now is 02:11 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com