PDA

View Full Version : [SOLVED:] How To Change VBA Copy Rows "X" Number of Times



jnix612
02-24-2022, 08:34 AM
I would like to use this code to paste "X" number of times to the next empty column to the right.

It works great as is, but I now have a different need.




Sub CopyxTimes()
Dim i As Integer
Dim Rng As Range
i = InputBox("Enter no of times")
Set Rng = Selection
Set Rng = Range("a2:s12")
Rng.Copy Rng.Offset(Rng.Rows.Count).Resize(Rng.Rows.Count * i, Rng.Columns.Count)
End Sub

Bob Phillips
02-24-2022, 09:05 AM
Sub CopyxTimes()
Dim x As Long
Dim Rng As Range
x = InputBox("Enter no of times")
Set Rng = Range("A2:S12")
Rng.Copy Rng.Offset(, Rng.Columns.Count).Resize(Rng.Rows.Count, Rng.Columns.Count * x)
End Sub

jnix612
02-24-2022, 09:16 AM
Works great. Thank you, thank you, thank you. I really appreciate your skill.

snb
02-24-2022, 01:23 PM
Or

Sub M_snb()
With Range("A2:S12")
.Copy .Offset(, .Columns.Count).Resize(, .Columns.Count * InputBox("no of times"))
End With
End Sub

jnix612
02-25-2022, 09:41 AM
Thank you snb :clap: