alexluchini
New Member
- Joined
- Mar 14, 2014
- Messages
- 4
Hello,
After a couple of hours of Googling and checking out these forums I decided to register and ask for help. I need a Macro that will Copy/Paste a selection of cells (that could change) "N" times vertically, without changing the order of the pasted selection.
I found a macro which ALMOST did what I wanted and I started hacking at it, this is close but still not correct, and it has errors:
Sub test()
Dim x As Integer
x = Application.InputBox("Number of Rows", "Number of Rows", Type:=1)
If x = False Then Exit Sub
Selection.Copy
Range(Selection.Offset(0), Selection.Offset(x)).EntireRow.Insert
Application.CutCopyMode = False
End Sub
Behavior:
I select a range, run the macro and an input box pops up asking how many times I'd like to paste the selected range. Perfect. The problem is, it doesn't offset and paste correctly.
Expected behavior:
When I enter the number of times I'd like to paste the range I'd like it to paste the range (without sorting, and keeping any formulas intact) vertically.
For example, if my Selected Range looked like this (keeping in mind my selected range could change):
[TABLE="width: 335"]
<colgroup><col><col><col></colgroup><tbody>[TR]
[TD]Col A[/TD]
[TD]Col B[/TD]
[TD]Col C[/TD]
[/TR]
[TR]
[TD]Text 1[/TD]
[TD]Text 1[/TD]
[TD]Text 1[/TD]
[/TR]
[TR]
[TD]Text 2[/TD]
[TD]Text 2[/TD]
[TD]Text 2[/TD]
[/TR]
[TR]
[TD]Text 3[/TD]
[TD]Text 3[/TD]
[TD]Text 3[/TD]
[/TR]
</tbody>[/TABLE]
I would want my pasted data to look like this:
[TABLE="width: 335"]
<colgroup><col><col><col></colgroup><tbody>[TR]
[TD]Col A[/TD]
[TD]Col B[/TD]
[TD]Col C[/TD]
[/TR]
[TR]
[TD]Text 1[/TD]
[TD]Other Text 1[/TD]
[TD]More Text 1[/TD]
[/TR]
[TR]
[TD]Text 2[/TD]
[TD]Other Text 2[/TD]
[TD]More Text 2[/TD]
[/TR]
[TR]
[TD]Text 3[/TD]
[TD]Other Text 3[/TD]
[TD]More Text 3[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Text 1[/TD]
[TD]Other Text 1[/TD]
[TD]More Text 1[/TD]
[/TR]
[TR]
[TD]Text 2[/TD]
[TD]Other Text 2[/TD]
[TD]More Text 2[/TD]
[/TR]
[TR]
[TD]Text 3[/TD]
[TD]Other Text 3[/TD]
[TD]More Text 3[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Text 1[/TD]
[TD]Other Text 1[/TD]
[TD]More Text 1[/TD]
[/TR]
[TR]
[TD]Text 2[/TD]
[TD]Other Text 2[/TD]
[TD]More Text 2[/TD]
[/TR]
[TR]
[TD]Text 3[/TD]
[TD]Other Text 3[/TD]
[TD]More Text 3[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Text 1[/TD]
[TD]Other Text 1[/TD]
[TD]More Text 1[/TD]
[/TR]
[TR]
[TD]Text 2[/TD]
[TD]Other Text 2[/TD]
[TD]More Text 2[/TD]
[/TR]
[TR]
[TD]Text 3[/TD]
[TD]Other Text 3[/TD]
[TD]More Text 3[/TD]
[/TR]
</tbody>[/TABLE]
Any help I can get would be much appreciated! Thank you.
After a couple of hours of Googling and checking out these forums I decided to register and ask for help. I need a Macro that will Copy/Paste a selection of cells (that could change) "N" times vertically, without changing the order of the pasted selection.
I found a macro which ALMOST did what I wanted and I started hacking at it, this is close but still not correct, and it has errors:
Sub test()
Dim x As Integer
x = Application.InputBox("Number of Rows", "Number of Rows", Type:=1)
If x = False Then Exit Sub
Selection.Copy
Range(Selection.Offset(0), Selection.Offset(x)).EntireRow.Insert
Application.CutCopyMode = False
End Sub
Behavior:
I select a range, run the macro and an input box pops up asking how many times I'd like to paste the selected range. Perfect. The problem is, it doesn't offset and paste correctly.
Expected behavior:
When I enter the number of times I'd like to paste the range I'd like it to paste the range (without sorting, and keeping any formulas intact) vertically.
For example, if my Selected Range looked like this (keeping in mind my selected range could change):
[TABLE="width: 335"]
<colgroup><col><col><col></colgroup><tbody>[TR]
[TD]Col A[/TD]
[TD]Col B[/TD]
[TD]Col C[/TD]
[/TR]
[TR]
[TD]Text 1[/TD]
[TD]Text 1[/TD]
[TD]Text 1[/TD]
[/TR]
[TR]
[TD]Text 2[/TD]
[TD]Text 2[/TD]
[TD]Text 2[/TD]
[/TR]
[TR]
[TD]Text 3[/TD]
[TD]Text 3[/TD]
[TD]Text 3[/TD]
[/TR]
</tbody>[/TABLE]
I would want my pasted data to look like this:
[TABLE="width: 335"]
<colgroup><col><col><col></colgroup><tbody>[TR]
[TD]Col A[/TD]
[TD]Col B[/TD]
[TD]Col C[/TD]
[/TR]
[TR]
[TD]Text 1[/TD]
[TD]Other Text 1[/TD]
[TD]More Text 1[/TD]
[/TR]
[TR]
[TD]Text 2[/TD]
[TD]Other Text 2[/TD]
[TD]More Text 2[/TD]
[/TR]
[TR]
[TD]Text 3[/TD]
[TD]Other Text 3[/TD]
[TD]More Text 3[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Text 1[/TD]
[TD]Other Text 1[/TD]
[TD]More Text 1[/TD]
[/TR]
[TR]
[TD]Text 2[/TD]
[TD]Other Text 2[/TD]
[TD]More Text 2[/TD]
[/TR]
[TR]
[TD]Text 3[/TD]
[TD]Other Text 3[/TD]
[TD]More Text 3[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Text 1[/TD]
[TD]Other Text 1[/TD]
[TD]More Text 1[/TD]
[/TR]
[TR]
[TD]Text 2[/TD]
[TD]Other Text 2[/TD]
[TD]More Text 2[/TD]
[/TR]
[TR]
[TD]Text 3[/TD]
[TD]Other Text 3[/TD]
[TD]More Text 3[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Text 1[/TD]
[TD]Other Text 1[/TD]
[TD]More Text 1[/TD]
[/TR]
[TR]
[TD]Text 2[/TD]
[TD]Other Text 2[/TD]
[TD]More Text 2[/TD]
[/TR]
[TR]
[TD]Text 3[/TD]
[TD]Other Text 3[/TD]
[TD]More Text 3[/TD]
[/TR]
</tbody>[/TABLE]
Any help I can get would be much appreciated! Thank you.