Loop through variable names

A

Andrew@Rays

Hi,

I have 5 variable names. They are Name_1, Name_2, Name_3, Name_4, Name_5

How can I loop through them?

for example:

For I = 1 to 5
Activecell.formula = Name_I.text
end if


Andrew
100909
 
R

Ron Rosenfeld

Hi,

I have 5 variable names. They are Name_1, Name_2, Name_3, Name_4, Name_5

How can I loop through them?

for example:

For I = 1 to 5
Activecell.formula = Name_I.text
end if


Andrew
100909

Put the names into an array:

===========================
Option Explicit
Sub foo()
Dim aVarNames() As Variant
Dim i As Long

aVarNames = Array("Name_1", "Name_2", "Name_3", "Name_4", "Name_5")

For i = 0 To UBound(aVarNames)
Range("a1").Offset(i, 0).Formula = aVarNames(i)
Next i

End Sub
=============================
--ron
 
A

Andrew@Rays

Hi Ron,

Thanks for your reply but it doesn't really help my needs. I tried to
simplify my request and you provided an answer for that.

I'm not very good with arrays.

My real request is I have a control with 38 check boxes on it. I wanted to
loop through each of them and record whether they're chacked or not. Then
I'm going to place the results on a worksheet (each of the controls relate to
a column).

Sorry for wasting your time the first time....
 
J

Jacob Skaria

'If you are talking about controls placed in userform try the below
For intTemp = 1 To 4
If ActiveSheet.OLEObjects("CheckBox" & intTemp).Object.Value = True Then
GetCheckBoxValue = GetCheckBoxValue + 1
End If
Next

'If the controls are placed in Activesheet then try the below
Dim ws As Worksheet, obj As OLEObject
Set ws = Sheets("Sheet1")
For Each obj In ws.OLEObjects
If TypeName(obj.Object) = "CheckBox" Then


End If
Next obj

If this post helps click Yes
 
R

Ron Rosenfeld

Hi Ron,

Thanks for your reply but it doesn't really help my needs. I tried to
simplify my request and you provided an answer for that.

I'm not very good with arrays.

My real request is I have a control with 38 check boxes on it. I wanted to
loop through each of them and record whether they're chacked or not. Then
I'm going to place the results on a worksheet (each of the controls relate to
a column).

Sorry for wasting your time the first time....

If Jacob's suggestions don't help, you'll have to be more specific and post
your code.
--ron
 

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

Top