Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Variable TextBox

Dear All
Following code is simple:

.....
For i=1 To 7
Worksheets("Sheet"&i).Range("A1").Value = i*2
Next i
.....

But if I want to do that with a TextBox how can I do that if I have
TextBox1 to TextBox7:

.....
For i=1 To 7
TextBox i .Value = i*2
Next i
.....

How do I program the line within the loop? I know, it would not work
like that.


Thanks Philipp

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Variable TextBox

I found a way to do it:
For i=1 To 7
Dim ctl As Control
For Each ctl In Controls
If TypeName(ctl) = "TextBox" Then
If ctl.Name = "TextBox" &i Then
ctl.Value = i*2
End If
End If
Next
Next i

If someone knows a more elgant way please let me know.
Cheer Philipp

Philipp Schramek schrieb:
Dear All
Following code is simple:

....
For i=1 To 7
Worksheets("Sheet"&i).Range("A1").Value = i*2
Next i
....

But if I want to do that with a TextBox how can I do that if I have
TextBox1 to TextBox7:

....
For i=1 To 7
TextBox i .Value = i*2
Next i
....

How do I program the line within the loop? I know, it would not work
like that.


Thanks Philipp


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Variable TextBox

For i=1 To 7
Userform1.Controls("TextBox" &i).Value = i*2
Next i


Might be a bit more compact.

--
Regards,
Tom Ogilvy



"Philipp Schramek" wrote in message
...
I found a way to do it:
For i=1 To 7
Dim ctl As Control
For Each ctl In Controls
If TypeName(ctl) = "TextBox" Then
If ctl.Name = "TextBox" &i Then
ctl.Value = i*2
End If
End If
Next
Next i

If someone knows a more elgant way please let me know.
Cheer Philipp

Philipp Schramek schrieb:
Dear All
Following code is simple:

....
For i=1 To 7
Worksheets("Sheet"&i).Range("A1").Value = i*2
Next i
....

But if I want to do that with a TextBox how can I do that if I have
TextBox1 to TextBox7:

....
For i=1 To 7
TextBox i .Value = i*2
Next i
....

How do I program the line within the loop? I know, it would not work
like that.


Thanks Philipp




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
Runtime Error '91' Object variable or With block variable not set Alec Coliver Excel Discussion (Misc queries) 2 October 24th 09 02:29 PM
Calculate Textbox value based on another textbox value.doc Tdungate Excel Discussion (Misc queries) 1 February 12th 09 07:11 PM
Calculate Textbox value based on another textbox value Tdungate Excel Discussion (Misc queries) 0 February 12th 09 07:03 PM
variable height variable width stacked bar charts ambthiru Charts and Charting in Excel 3 January 18th 06 11:41 PM
why is it saying sheetcnt is "variable not defined" how to do a global variable to share over multiple functions in vba for excel? Daniel Excel Worksheet Functions 1 July 9th 05 03:05 AM


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

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

About Us

"It's about Microsoft Excel"