ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Form (https://www.excelbanter.com/excel-programming/365939-form.html)

Bill[_30_]

Form
 
Hello,
I have a form that contains a number of text boxes. I would like to add a
loop that sets each text box to an initial value such as 1. Each textbox is
cleverly names TextBox1, TextBox2. I tried a loop like:

For i = 1 to 10
userform1.textbox " & i = 1
next i

But that doesn't work. Any help?

Thanks.

Bill



Duncan[_5_]

Form
 
For Each cntrl In Me.Controls
On Error Resume Next
If TypeOf cntrl Is MSForms.TextBox Then
cntrl.Value = "1"
End If
Next cntrl


I think this should do it, havent tested though so post back and let us
know either way.

Duncan


Bill wrote:

Hello,
I have a form that contains a number of text boxes. I would like to add a
loop that sets each text box to an initial value such as 1. Each textbox is
cleverly names TextBox1, TextBox2. I tried a loop like:

For i = 1 to 10
userform1.textbox " & i = 1
next i

But that doesn't work. Any help?

Thanks.

Bill



Norman Jones

Form
 
Hi Bill,

Try:

For i = 1 to 10
Userform1.Controls("Textbox" & i).Text = ""
Next i



---
Regards,
Norman



"Bill" wrote in message
k.net...
Hello,
I have a form that contains a number of text boxes. I would like to add a
loop that sets each text box to an initial value such as 1. Each textbox
is cleverly names TextBox1, TextBox2. I tried a loop like:

For i = 1 to 10
userform1.textbox " & i = 1
next i

But that doesn't work. Any help?

Thanks.

Bill




Bill[_30_]

Form
 
Worked great. Thanks!

"Duncan" wrote in message
oups.com...
For Each cntrl In Me.Controls
On Error Resume Next
If TypeOf cntrl Is MSForms.TextBox Then
cntrl.Value = "1"
End If
Next cntrl


I think this should do it, havent tested though so post back and let us
know either way.

Duncan


Bill wrote:

Hello,
I have a form that contains a number of text boxes. I would like to add
a
loop that sets each text box to an initial value such as 1. Each textbox
is
cleverly names TextBox1, TextBox2. I tried a loop like:

For i = 1 to 10
userform1.textbox " & i = 1
next i

But that doesn't work. Any help?

Thanks.

Bill





Duncan[_5_]

Form
 
Bill,

If you was saying that my loop worked then I just point out, using this
way means you can change the names of the textboxes, and can add more
without affecting the loop.

But both ways work just the same, a case of whether you want certain
textboxes excluded from your loop really.

Duncan




Bill wrote:

Worked great. Thanks!

"Duncan" wrote in message
oups.com...
For Each cntrl In Me.Controls
On Error Resume Next
If TypeOf cntrl Is MSForms.TextBox Then
cntrl.Value = "1"
End If
Next cntrl


I think this should do it, havent tested though so post back and let us
know either way.

Duncan


Bill wrote:

Hello,
I have a form that contains a number of text boxes. I would like to add
a
loop that sets each text box to an initial value such as 1. Each textbox
is
cleverly names TextBox1, TextBox2. I tried a loop like:

For i = 1 to 10
userform1.textbox " & i = 1
next i

But that doesn't work. Any help?

Thanks.

Bill





All times are GMT +1. The time now is 10:36 AM.

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