ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   looping and objects (https://www.excelbanter.com/excel-programming/303754-looping-objects.html)

Rune[_2_]

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??



JE McGimpsey

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??


Rune[_2_]

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??




Tom Ogilvy

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??




Tom Ogilvy

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??






Rune[_2_]

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??








JE McGimpsey

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?



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

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