Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- EXCEL
- ====
- Copy every now x number of times based on number in a column
- 1. open workbook
- 2. press ALT+F11
- 3. Insert>Add module
- 4. paste the code below
- 5. Run by clicking the 'play' button or press F5 or in Excel choose tools>macro>run
- NOTE: make sure your table starts in column A and the number representing the number of times you want to copy that row should be modified in the code below (currently it is "B", change every instance of "B" to the column containing the numbers).
- Sub CopyData()
- Dim lRow As Long
- Dim RepeatFactor As Variant
- lRow = 1
- Do While (Cells(lRow, "A") <> "")
- RepeatFactor = Cells(lRow, "B")
- If ((RepeatFactor > 1) And IsNumeric(RepeatFactor)) Then
- Range(Cells(lRow, "A"), Cells(lRow, "B")).Copy
- Range(Cells(lRow + 1, "A"), Cells(lRow + RepeatFactor - 1, "B")).Select
- Selection.Insert Shift:=xlDown
- lRow = lRow + RepeatFactor - 1
- End If
- lRow = lRow + 1
- Loop
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement