Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default 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?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default 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?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default 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?

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Loop with variable name? Mike Excel Discussion (Misc queries) 6 April 25th 09 05:12 AM
loop for-next with variable end Valeria Excel Programming 6 November 30th 07 04:14 PM
Loop and variable type Arne Hegefors Excel Programming 1 November 5th 07 08:39 AM
For Each ... Next loop - need to reference the loop variable [email protected] Excel Programming 4 July 13th 06 06:12 PM
Loop with variable Knut Excel Programming 2 November 19th 05 02:48 PM


All times are GMT +1. The time now is 08:04 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"