#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 89
Default 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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 290
Default 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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default 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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 89
Default 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




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 290
Default 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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
excel form. Need data extracted to spreadsheet each time a form co MikeR-Oz Excel Discussion (Misc queries) 4 April 5th 09 05:18 AM
Using a template form, advance a form number everytime you open ShoDan Excel Discussion (Misc queries) 1 January 31st 08 01:34 PM
Pass variable from form to form to form headly Excel Programming 1 May 31st 06 02:50 AM
Strange issue freezing parent form when unloading a child form Stefano Gatto Excel Programming 1 November 11th 05 04:42 PM
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? Daniel[_14_] Excel Programming 1 August 29th 04 01:20 PM


All times are GMT +1. The time now is 09:55 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"