ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Looping through TextBoxes (https://www.excelbanter.com/excel-programming/436735-re-looping-through-textboxes.html)

Dave Peterson

Looping through TextBoxes
 
If you're in the userform_initialize event (or anywhere in the userform module),
you could use:

With Me
(instead of With Userform1)

so

dim iCtr as long
for ictr = 1 to 13 'lbound(myArray) to ubound(myArray)
me.controls("txbox" & ictr).value = myarray(ictr)
next ictr

The names and array bounds have to be in sync.

Al_82 wrote:

I have a UserForm with an array of TextBoxes that allows the user to edit
selected data arrays from a larger database. To load these TextBoxes I can
use a brute force method:

With UserForm1
.txBox1 = array(1)
.txBox2 = array(2)
etc

but it would obviously be better to do this in a loop. My problem is I
cant figure how to synthesize the TextBox names so I can use a loop to
functionally do:

.txBoxn= array(n)
Can someone tell me how to do this?

--
Al_82


--

Dave Peterson

Al_82

Looping through TextBoxes
 
Perfect, Dave.

Thanks.
--
Al_82


"Dave Peterson" wrote:

If you're in the userform_initialize event (or anywhere in the userform module),
you could use:

With Me
(instead of With Userform1)

so

dim iCtr as long
for ictr = 1 to 13 'lbound(myArray) to ubound(myArray)
me.controls("txbox" & ictr).value = myarray(ictr)
next ictr

The names and array bounds have to be in sync.

Al_82 wrote:

I have a UserForm with an array of TextBoxes that allows the user to edit
selected data arrays from a larger database. To load these TextBoxes I can
use a brute force method:

With UserForm1
.txBox1 = array(1)
.txBox2 = array(2)
etc

but it would obviously be better to do this in a loop. My problem is I
canĂ¢‚¬„¢t figure how to synthesize the TextBox names so I can use a loop to
functionally do:

.txBoxn= array(n)
Can someone tell me how to do this?

--
Al_82


--

Dave Peterson
.



All times are GMT +1. The time now is 12:31 PM.

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