looping and objects

R

Rune

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

JE McGimpsey

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
 
R

Rune

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

Tom Ogilvy

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
 
J

JE McGimpsey

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.
 
Top