looping and objects

  • Thread starter Thread starter Rune
  • Start date Start date
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??
 
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
 
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 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
 
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top