ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   LAST value of loop to be a variable (https://www.excelbanter.com/excel-programming/402249-last-value-loop-variable.html)

Berj

LAST value of loop to be a variable
 
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?

Gary''s Student

LAST value of loop to be a variable
 
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
..
..
..

--
Gary''s Student - gsnu200760


"Berj" wrote:

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?


Mike H

LAST value of loop to be a variable
 
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

"Berj" wrote:

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?



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

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