Perform a macro a specified number of times

  • Thread starter Thread starter KLynnB
  • Start date Start date
K

KLynnB

Hello All,

I'm working on a spreadsheet that will calculate arrears for a numbe
of months. The number of months will change each time the calculatio
is run.

I need to copy and paste the calculation formulas by using a macro tha
will repeat the copy and paste function the number of months. I'v
recorded a simple copy and paste macro.

How do I modify the macro to read the calculated number of months in
specific cell and then repeat itself by the number of months?

I hope this makes sense!

KLynn

"When in danger or in doubt, run in circles, scream and shout." ~Dor
Lon
 
Hi,

Can you give us some more information so we can
better understand what it is you have so far?
and what you need?

jeff
 
This is one way

Sub RunXTimes(Optional pIdx)
Dim i As Long

'your code here

If IsMissing(pIdx) Then
For i = 2 To Range("H1").Value
RunXTimes i
Next i
Else
MsgBox "hello " & pIdx
End If

End Sub


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Surely.

I have a formula =DATE(YEAR(C14),MONTH(C14)+1,DAY(C14)) whic
calculates the number of months I need to run the arrears calculation.

I have another formula =DATE(YEAR(C14),MONTH(C14)+1,DAY(C14)) that add
one month to the starting month.

I need to be able to copy the above formula the number of months fo
which I need to calculate arrears.

I've recorded the following macro:

Selection.Copy
Range("C16").Select
ActiveSheet.Paste
End Sub

Is there a way to modify this macro to repeat itself by the number o
months?

I'm afraid I know little to nothing about visual basic.

Thanks,

KLyn
 

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

Back
Top