0

I would like a macro to execute a number of times equal to the integer value in a specific cell

When Cell "A1" is populated with a positive whole number integer, I want the following macro to run a number of times equal to that integer.

Sub CopyRow()
  Rows("2:2").Select
  Selection.Copy
  Rows("3:3").Select
  Selection.Insert Shift:=xlDown
Application.CutCopyMode = False
End Sub
Mikku
  • 6,538
  • 3
  • 15
  • 38
  • 1
    You should be adding your macro in worksheet change event: https://stackoverflow.com/questions/10474356/vba-worksheet-change-event – Gangula Aug 13 '19 at 04:19
  • I also recommend what @Gangula mentioned. However you will have to take care of lot of this while using that. For example **[1.]** Checking for valid integer value **[2.]** Events and Handling Change event. **[3.]** This is a [good read](https://stackoverflow.com/questions/13860894/why-ms-excel-crashes-and-closes-during-worksheet-change-sub-procedure/13861640#13861640) and will definitely help you. – Siddharth Rout Aug 13 '19 at 04:51

1 Answers1

1

Try This Macro

Sub Add_rows()
Rows(2).Copy
  Rows(2 & ":" & [A1] + 1).Insert
End Sub