LAST value of loop to be a variable

B

Berj

Hi all.

Consider the following:

Sub Macro41()
' Print ALL
Dim x As Integer
For x = 1 To 5
Call Over7A
Application.Run ("Macro" & x)
Call Last7A
Next x
End Sub


I want the number 5 (the final value of the loop) to be the contents of cell
C2 of the current sheet of a file named ‘Name List.xls’.

Can Anybody Help?
 
G

Gary''s Student

We don't need to know the current sheet in Name List, just go there and come
back:

Workbooks("Name List.xls").Activate
n = Range("C2").Value
Workbooks("Book1.xls").Activate
For x = 1 To n
..
..
..
 
M

Mike H

maybe

Sub Macro41()
myvar = Workbooks("Name List.xls").ActiveSheet.Range("C2")

Dim x As Integer
For x = 1 To myvar
'do your stuff
Next x
End Sub

Mike
 

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