Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Hru48
 
Posts: n/a
Default getting a macro to run X amount of times..


Hey all,

I have a macro that I need to run the amount of time equal to the last
value in a list which will change in a monthly basis.

I tried to get it with a for loop but I don't know how to get it to run
a cetain amount of times, should I be using some kind of count and array
or is there a very simple way of doing this.

The macro is below if any one has any thoughts:




Sub tesIncrement20()



Range("D108:R108").Select
Selection.Copy
Windows("test").Activate
Sheets("cal").Select
Range("B1").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=False
Application.CutCopyMode = False
Selection.Insert Shift:=xlDown
Windows("North_central_agent.xls").Activate
ActiveWindow.ScrollWorkbookTabs Position:=xlLast
Sheets("Reference").Select
Windows("test").Activate


Range("A1").Select
Selection.Delete Shift:=xlUp
Selection.Copy
Windows("North_central_agent.xls").Activate
Range("H103").Select
ActiveSheet.Paste
ActiveWindow.ScrollWorkbookTabs Position:=xlFirst
Sheets("Summary").Select
Windows("test").Activate
Range("B1").Select
Application.CutCopyMode = False
Windows("North_central_agent.xls").Activate



End Sub


--
Hru48
------------------------------------------------------------------------
Hru48's Profile: http://www.excelforum.com/member.php...o&userid=24895
View this thread: http://www.excelforum.com/showthread...hreadid=397177

  #2   Report Post  
Dave O
 
Posts: n/a
Default

Just to make sure I understand: you have a list of data that changes
from month to month, and the last cell in that list contains an integer
number that represents the number of loops your program requires.

Or did I misunderstand, and instead you need your macro to run until it
encounters the last value in the list, which changes from month to
month.

If it's the first scenario, you can declare an integer variable- I use
K (short for Kounter), and another integer variable, maybe something
like LoopNum. Assign the value in the last cell to LoopNum, and then
start a For loop with this syntax:
For K = 1 to LoopNum
{your code here}
Next K

That's an idea, but it would be helpful to see a sample of your data.

  #3   Report Post  
Earl Kiosterud
 
Posts: n/a
Default

Hru,

There may be more than one question here -- How to find the last cell of a
list whose length changes, or how to get it to loop according to the value
in that cell.

If the cell in the last item of the list will not move, then do something
like this:

Dim i as long
Dim LoopCount as long

LoopCount = Range( last cell )
for i = 1 to LoopCount
code goes here
next i

--
Earl Kiosterud
www.smokeylake.com

"Hru48" wrote in
message ...

Hey all,

I have a macro that I need to run the amount of time equal to the last
value in a list which will change in a monthly basis.

I tried to get it with a for loop but I don't know how to get it to run
a cetain amount of times, should I be using some kind of count and array
or is there a very simple way of doing this.

The macro is below if any one has any thoughts:




Sub tesIncrement20()



Range("D108:R108").Select
Selection.Copy
Windows("test").Activate
Sheets("cal").Select
Range("B1").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=False
Application.CutCopyMode = False
Selection.Insert Shift:=xlDown
Windows("North_central_agent.xls").Activate
ActiveWindow.ScrollWorkbookTabs Position:=xlLast
Sheets("Reference").Select
Windows("test").Activate


Range("A1").Select
Selection.Delete Shift:=xlUp
Selection.Copy
Windows("North_central_agent.xls").Activate
Range("H103").Select
ActiveSheet.Paste
ActiveWindow.ScrollWorkbookTabs Position:=xlFirst
Sheets("Summary").Select
Windows("test").Activate
Range("B1").Select
Application.CutCopyMode = False
Windows("North_central_agent.xls").Activate



End Sub


--
Hru48
------------------------------------------------------------------------
Hru48's Profile:
http://www.excelforum.com/member.php...o&userid=24895
View this thread: http://www.excelforum.com/showthread...hreadid=397177



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
I need to find out how to multiply gross hours times amount of pay. Marc New Users to Excel 3 August 10th 05 03:38 AM
How do I set a macro to run at specific times? Nick123 Excel Discussion (Misc queries) 1 July 26th 05 06:19 PM
How do I find the amount of hours between times? gormanj Excel Discussion (Misc queries) 1 May 4th 05 12:26 PM
Date macro Hiking Excel Discussion (Misc queries) 9 February 3rd 05 12:40 AM
Can you limit the amount of times a calc is performed on certain cells n_davies Excel Discussion (Misc queries) 1 January 24th 05 10:43 PM


All times are GMT +1. The time now is 05:39 AM.

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"