Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
excel form. Need data extracted to spreadsheet each time a form co | Excel Discussion (Misc queries) | |||
Using a template form, advance a form number everytime you open | Excel Discussion (Misc queries) | |||
Pass variable from form to form to form | Excel Programming | |||
Strange issue freezing parent form when unloading a child form | Excel Programming | |||
Is it possible to open the VBA form with a link in a sheet and to pass variable from a cell to the VBA form? | Excel Programming |