Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default looping and objects

I'm a newbie and have this problem:

I have 13 textboxes called MN1, MN2, MN3 ...... MN13
when trying to set text in all of them i did this:

for i 1 to 13
Dim Temp as object
Set Temp = "MN" & i
temp.text = "test"
next i

How do i refer to an object whith i in a loop??


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default looping and objects

One way:

Dim i As Long
For i = 1 to ActiveSheet.Textboxes.Count
ActiveSheet.Textboxes(i).Text = "test"
Next i


Another:

Dim tbTemp As TextBox
For Each tbTemp In ActiveSheet.TextBoxes
tbTemp.Text = "test"
Next tbTemp


In article ,
"Rune" wrote:

I'm a newbie and have this problem:

I have 13 textboxes called MN1, MN2, MN3 ...... MN13
when trying to set text in all of them i did this:

for i 1 to 13
Dim Temp as object
Set Temp = "MN" & i
temp.text = "test"
next i

How do i refer to an object whith i in a loop??

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default looping and objects

i didnt understand that....
all of the textboxes is in a form not on a sheet

if i want to change the text in lats say MN2 using "MN" an i (or any index
letter) how do i do that?


"JE McGimpsey" wrote in message
...
One way:

Dim i As Long
For i = 1 to ActiveSheet.Textboxes.Count
ActiveSheet.Textboxes(i).Text = "test"
Next i


Another:

Dim tbTemp As TextBox
For Each tbTemp In ActiveSheet.TextBoxes
tbTemp.Text = "test"
Next tbTemp


In article ,
"Rune" wrote:

I'm a newbie and have this problem:

I have 13 textboxes called MN1, MN2, MN3 ...... MN13
when trying to set text in all of them i did this:

for i 1 to 13
Dim Temp as object
Set Temp = "MN" & i
temp.text = "test"
next i

How do i refer to an object whith i in a loop??



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default looping and objects

JE shows how to do it with a textbox from the drawing toolbar or on a
MACintosh. For an activeX textbox in Windows

Dim oleObj as OleObject
for each oleObj in activesheet.OleObjects
if typeof oleObj.Object is MSforms.Textbox then
oleObj.Object.Value = "Test"
end if
Next

or if you have more than these textboxes

for i = 1 to 13
activesheet.OleObjects("MN" & i ).Value = "Test"
Next

--
Regards,
Tom Ogilvy


"JE McGimpsey" wrote in message
...
One way:

Dim i As Long
For i = 1 to ActiveSheet.Textboxes.Count
ActiveSheet.Textboxes(i).Text = "test"
Next i


Another:

Dim tbTemp As TextBox
For Each tbTemp In ActiveSheet.TextBoxes
tbTemp.Text = "test"
Next tbTemp


In article ,
"Rune" wrote:

I'm a newbie and have this problem:

I have 13 textboxes called MN1, MN2, MN3 ...... MN13
when trying to set text in all of them i did this:

for i 1 to 13
Dim Temp as object
Set Temp = "MN" & i
temp.text = "test"
next i

How do i refer to an object whith i in a loop??



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default looping and objects

for i = 1 to 13
userform1.controls("MN" & i).Text = "Test"
Next i

--
Regards,
Tom Ogilvy


"Rune" wrote in message
...
i didnt understand that....
all of the textboxes is in a form not on a sheet

if i want to change the text in lats say MN2 using "MN" an i (or any index
letter) how do i do that?


"JE McGimpsey" wrote in message
...
One way:

Dim i As Long
For i = 1 to ActiveSheet.Textboxes.Count
ActiveSheet.Textboxes(i).Text = "test"
Next i


Another:

Dim tbTemp As TextBox
For Each tbTemp In ActiveSheet.TextBoxes
tbTemp.Text = "test"
Next tbTemp


In article ,
"Rune" wrote:

I'm a newbie and have this problem:

I have 13 textboxes called MN1, MN2, MN3 ...... MN13
when trying to set text in all of them i did this:

for i 1 to 13
Dim Temp as object
Set Temp = "MN" & i
temp.text = "test"
next i

How do i refer to an object whith i in a loop??







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default looping and objects

Thank you!!!.. that solved my problem :D



"Tom Ogilvy" wrote in message
...
for i = 1 to 13
userform1.controls("MN" & i).Text = "Test"
Next i

--
Regards,
Tom Ogilvy


"Rune" wrote in message
...
i didnt understand that....
all of the textboxes is in a form not on a sheet

if i want to change the text in lats say MN2 using "MN" an i (or any

index
letter) how do i do that?


"JE McGimpsey" wrote in message
...
One way:

Dim i As Long
For i = 1 to ActiveSheet.Textboxes.Count
ActiveSheet.Textboxes(i).Text = "test"
Next i


Another:

Dim tbTemp As TextBox
For Each tbTemp In ActiveSheet.TextBoxes
tbTemp.Text = "test"
Next tbTemp


In article ,
"Rune" wrote:

I'm a newbie and have this problem:

I have 13 textboxes called MN1, MN2, MN3 ...... MN13
when trying to set text in all of them i did this:

for i 1 to 13
Dim Temp as object
Set Temp = "MN" & i
temp.text = "test"
next i

How do i refer to an object whith i in a loop??







  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default looping and objects

Within the userform:

Me.Controls("MN" & i).Text = "test"


External to the userform:

MyForm.Controls("MN" & i).Text = "test"


where MyForm is your userform instance.



In article ,
"Rune" wrote:

i didnt understand that....
all of the textboxes is in a form not on a sheet

if i want to change the text in lats say MN2 using "MN" an i (or any index
letter) how do i do that?

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
Looping Maggie[_6_] Excel Discussion (Misc queries) 6 October 2nd 08 09:14 PM
Not Looping Roger Excel Discussion (Misc queries) 0 February 26th 08 05:18 PM
looping to End Nabeel Moeen Excel Programming 2 February 25th 04 10:52 AM
Looping Andrew Clark[_2_] Excel Programming 1 December 20th 03 05:01 PM
Looping Syd[_4_] Excel Programming 1 December 11th 03 11:17 PM


All times are GMT +1. The time now is 09:48 AM.

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"