Looping a macro x times(x being activecell.value)?

  • Thread starter Thread starter Shaka215
  • Start date Start date
S

Shaka215

How do I loop a macro x amount of times from activecell.value?
I need to have a macro repeat a process based on the value of say cell
"T21".
Please explain the loop process as detailed as possiable. Thank you
fellow programmers!

-Shaka215
 
Bonjour,

Dim iCnt as integer
For iCnt = 1 to Range("T21").value
Call MyMacro
Next iCnt

Et voilà!
 
How do I loop a macro x amount of times from activecell.value?
I need to have a macro repeat a process based on the value of say cell
"T21".
Please explain the loop process as detailed as possiable. Thank you
fellow programmers!

-Shaka215


Dear Shaka,

Just try the following code :-

Sub LoopTest()
Dim n
Dim V
Range("T21").Select
V = ActiveCell.Value
n = 0
Do Until n = V
'your code
n = n + 1
Loop
End Sub
 
Thanks! Worked great...
Dear Shaka,

Just try the following code :-

Sub LoopTest()
Dim n
Dim V
Range("T21").Select
V = ActiveCell.Value
n = 0
Do Until n = V
'your code
n = n + 1
Loop
End Sub
 
First off, this is my first post on this site and i'm excited. I've used
another site for years and recently i thought of looking at other sites-
and talk about a sign or something; after registering the first topic i
saw was the exact topic i was working on! WOW --- I think i've come to
the right place!!!!!!!!!!

so here we go


how would i adapt this code
============================================================
If [s6].Value = 1 Then Call addMC
If [r6].Value = 1 Then Call addJar
If [q6].Value = 1 Then Call add2oz
If [p6].Value = 1 Then Call add8oz
If [o6].Value = 1 Then Call add18oz
If [n6].Value = 1 Then Call add32oz
===========================================================

so that the macros that are called are run as many times as the value
in their respective cells.

Example: for the first line "If [s6].Value = 1 Then Call addMC" if cell
S6 = 12 then the Macro AddMC will be run 12 times and if cell S6 = 2
then the macro would only me run twice or even if S6 = 0 then the
macro would not be run. I think i've made my point. As you can see
there is more then 2 or so seperate macros their respective cells to
run every time this sub is run. Thanks
 
Back
Top